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

inserting date and time into database

 
sundeep
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can any one help me regading inserting and retriving date and time into and from database ..using sql
thanks in advance
 
Balki Dhar
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which database you are using? What is your JDBC driver?
Balki
 
sundeep
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Todd M Bush
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic