File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Issue with Date insertion

 
K Kiran Kumar
Ranch Hand
Posts: 109
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20208
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 109
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2577
11
C++ Linux Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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+")");
 
K Kiran Kumar
Ranch Hand
Posts: 109
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic