• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Issue with Date insertion

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic