Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MySQL date column conversion

Status
Not open for further replies.

ericbrunson

Technical User
Jan 9, 2004
2,092
0
0
US
I'm getting the following error after upgrading MySQL form 4.0.x to 4.1.5:

Code:
javax.ejb.EJBException: Cannot convert value '2004-09-27 11:38:45' from column 40(2004-09-27 11:38:45 ) to DATE.
        at qcigs.ejb.AdminBean.getOrders(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)

I'm using mysql-connector-java-3.0.15

Do I need to upgrade my jdbc driver or is this something I can fix in my schema?

Thanks
 
How are you setting the Date field via JDBC ? Using the java.sql.Timestamp class ?

--------------------------------------------------
Free Database Connection Pooling Software
 
It was the class doing it automatically. It seems it was trying to convert a timestamp field to a date and puking. I converted the field to a datetime and the code works now, but I lose the benefits of a timestamp field in mysql.
 
Can someone post me a simple snippet of how to set a mysql date field to the current date. So far I've waded through the manual pages for Date, Calendar, SimpleDateFormat, Java.sql, java.txt, java.util and about a dozen other pages. The simplest example I've found so far seems to involve about a 6 function calls and don't really work in my object structure.

Thanks
 
Code:
// eg with PreparedStatement
int index ...
PreparedStatement ps = ...
java.util.Date d = new java.util.Date();
long dNow = d.getTime();
java.sql.Timestamp ts = new java.sql.Timestamp(dNow);
ps.setTimestamp(index, ts);



--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top