This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes JDBC and the fly likes Insert a Date into DB JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "Insert a Date into DB JDBC" Watch "Insert a Date into DB JDBC" New topic
Author

Insert a Date into DB JDBC

Eric Qez
Greenhorn

Joined: Jan 19, 2004
Posts: 1
I need to insert a date variable into DB. The field in DB table is date. The date is in default format 'yyyy-mm-dd'. I try to use statement like this and didn't work. Any idea?
String wkEnding = "2004-01-19";
sql = "Insert into Timesheet Wk_Ending values( {d '" + wkEnding + "'} )";
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 26173
    
  66

Eric,
It's generally a good idea to use a prepared statement. That way, you do not have to worry about db specific formats.
What db are you using?


[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
 
I agree. Here's the link: http://jrebel.com/download
 
subject: Insert a Date into DB JDBC
 
Similar Threads
Superclass methods not able to acces
conversion from Date ojbect to Date object
insert and get date in postgresql
doubts in setDate(i,date,cal) API of preparedStatement
invalid column type exception on Oracle db