• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

jdbc and insert date how

 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have tried to insert date into mysql and Access
but always fail

how can i solve this problem
 
Bartender
Posts: 2662
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
Please show us what you tried.

Regards, Jan
 
author & internet detective
Posts: 41998
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 41998
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Stinging nettles are edible. But I really want to see you try to eat this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic