Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jdbc and insert date how

 
hassan ali
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have tried to insert date into mysql and Access
but always fail

how can i solve this problem
 
Jan Cumps
Bartender
Posts: 2584
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please show us what you tried.

Regards, Jan
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hassan,
What error do you get? Are you using a prepared statement? If not, this is a recommended and much easier way of doing so.
 
hassan ali
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have tried this.
long DATE= Date.parse("12/1/2006");

stat.executeUpdate("insert into ORDERS (CoustmerID,serviceID,service_details,order_no,date) values('"+keyCostumer+"','"+keyservice+"','"+keyservice_Details+"','"+OrderId+"','"+DATE+"')");

this error message

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Sy
ntax error in INSERT INTO statement.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hassan,
Access is expecting a specific format for the date. (Check your database documentation for the format.) it is definitely not a long with the number of milliseconds since 1970.

I still recommend a PraparedStatement as it avoids this issue and you can just pass a Java Date object in.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic