This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JDBC and the fly likes inserting date and time into database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "inserting date and time into database" Watch "inserting date and time into database" New topic
Author

inserting date and time into database

sundeep
Greenhorn

Joined: Apr 20, 2001
Posts: 5
can any one help me regading inserting and retriving date and time into and from database ..using sql
thanks in advance
Balki Dhar
Greenhorn

Joined: Dec 15, 2005
Posts: 18
Which database you are using? What is your JDBC driver?
Balki
sundeep
Greenhorn

Joined: Apr 20, 2001
Posts: 5
i am using ms access database
connecting to database , inserting and retriving from database of strings and numbers for me working ...problem is with inserting and retriving date and time into the data base
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
To insert/retrieve a date, you need to construct an insert statement in your java program that uses the functions in Access that convert to/from a string to the date data type.
Format converts from a date to a string for retrieving the date from the database and DateValue converts a string to a Date.


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Todd M Bush
Greenhorn

Joined: Apr 26, 2000
Posts: 22
I know using an Oracle database and Oracle's JDBC driver I can insert a date using this...
sSql = "insert into myTable value( {d '" + myDate + "'}";
The {d 'date' } is read my the JDBC driver and formats the date to the odd way Oracle stores it. myDate is a String formatted like "mm/dd/yyyy".
Whichever JDBC driver you are using might have the same functionality.
Hope this helps
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: inserting date and time into database