aspose file tools*
The moose likes JDBC and the fly likes jdbc and insert date how Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "jdbc and insert date how" Watch "jdbc and insert date how" New topic
Author

jdbc and insert date how

hassan ali
Ranch Hand

Joined: Apr 23, 2006
Posts: 127
i have tried to insert date into mysql and Access
but always fail

how can i solve this problem
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2510
    
  10

Please show us what you tried.

Regards, Jan


OCUP UML fundamental and ITIL foundation
youtube channel
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30938
    
158

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
hassan ali
Ranch Hand

Joined: Apr 23, 2006
Posts: 127
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

Joined: May 26, 2003
Posts: 30938
    
158

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jdbc and insert date how