Click to See Complete Forum and Search --> : Mapping sql date to java
AlaNio
03-06-2007, 10:44 AM
I'm having problems mapping a sql date type field to a java type. At the moment i'm getting it from the resultset using rs.getDate() which returns java.sql.date type. So i tried storing it in a variable with that type but am getting this error:
SQLSTATE 22007: An invalid datetime format was detected; that is, an invalid string representation or value was specified. SQLSTATE=22007
The date is in the database in the format mm/dd/yyyy
Any help on this would be appreciated
jasonahoule
03-06-2007, 06:09 PM
If you don't work with the date at all and you are simply displaying it, just retrieve it as a string. If not try posting the code that is causing the problem. It should look something like:
java.sql.Date date = resultset.getDate("date_column");
If you do need to perform calculations on the date, I ran into this problem while using InnoDB as the storage engine. Changing to MyISAM may help.
agent_x91
03-10-2007, 12:01 PM
As it happens, I've had problems trying to convert Java dates to MySQL dates before, everytime I tried to insert a date into the database it ended up as a null date which confused me but then my server exploded so I left it. I haven't used SQL much so I didn't look in the sql package anyway.
Anyway, this was helpful to me too so thanks, both of you :D
AlaNio
03-11-2007, 03:27 PM
you found a solution for mapping to sql? i need to add a date in the format mm/dd/yyyy.
AlaNio
03-24-2007, 07:49 PM
still havent found a solution for this. anyone have any ideas? just when i insert a date to the database i need to have it formatted as above
WebLoader
04-04-2007, 09:08 AM
One suggestion i know , there is a class named SimpleDateFormat in java.text package which can be used to convert String or date object to any kind of universal date'format and its supports plus and minus operations. and also there is a stored procedure in sql statement called Convert which can be used to convert your inputs as any kind of date'format,but in bussineses artitecture we do not use date mapping directly, we use millisecond as a counter beacause different DataBase System has different counter for counting date.