wood burning stoves*
The moose likes JDBC and the fly likes Issue with Date insertion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Issue with Date insertion" Watch "Issue with Date insertion" New topic
Author

Issue with Date insertion

K Kiran Kumar
Ranch Hand

Joined: Jan 04, 2006
Posts: 109
Hi,

I am trying to insert a date field to MS Access 2002 *.mdb file.
Below is the code I am using and my table structure is very simple
TEST12345(ff) -- the ff column is of type Date/Time



Whether I use createStatement or PrepareStatement, I get the below exception

java.sql.SQLException: General error
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLExecute(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(Unknown Source)
at com.smart.corp.dao.UpdateDAO.main(UpdateDAO.java:158)

Not sure where I am wrong. There is no problem with the connection object since I have created tables with it successfully. Any help on my issue would be highly appreciated.

Regards,
Kiran.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Seems to me that if the field's type is "Date/Time" then you should be using a Java class which matches that type. That would be java.sql.Timestamp and not java.sql.Date (which doesn't have a Time component).
K Kiran Kumar
Ranch Hand

Joined: Jan 04, 2006
Posts: 109
Thanks Paul. Timestamp worked for me only with PreparedStatement but not with Statement.
Am I missing anything in Statement? Please let me know. Below is mycode.


java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression '2009-10-08 11:41:38.984'.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(Unknown Source)
at com.smart.corp.dao.UpdateDAO.main(UpdateDAO.java:201)
java.lang.NullPointerException
at com.smart.corp.dao.UpdateDAO.main(UpdateDAO.java:217)



Regards,
Kiran.
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2497
    
    8

How would you insert this record if you would use an sql query tool?
How would you format the timestamp then?

Compare that with how your statement looks like in your javacode (Do System.out.println("insert into TEST12345(ff) values ("+ts+")");


OCUP UML fundamental and ITIL foundation
youtube channel
K Kiran Kumar
Ranch Hand

Joined: Jan 04, 2006
Posts: 109
Hi,
How would you insert this record if you would use an sql query tool?
I use TO_DATE('12-08-2009','DD-MM-YYYY') function.
How would you format the timestamp then?
In java there is no TO_DATE type method and hence trying to insert the Object.

The output for "insert into TEST12345(ff) values ("+ts+")"); is
insert into TEST12345(ff) values (2009-10-08 11:41:38.984)

Thanks for the suggestion.

Regards,
Kiran.
 
Don't get me started about those stupid light bulbs.
 
subject: Issue with Date insertion