my dog learned polymorphism*
The moose likes JDBC and the fly likes Date format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Date format" Watch "Date format" New topic
Author

Date format

Nick Davenport
Greenhorn

Joined: Jul 27, 2007
Posts: 12
I get my current date for PreparedStatement Oracle 9i insert like this:


I then use this for my insert setter:

Is there someway to format the entry that goes in the database?
It currently inputs this in the database: 2008-10-15 11:23:00.807
I would like this instead: 15-Oct-08 11:23:00 PM
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30789
    
157

Nick,
What data type do you have in the database? If it is Date/Timestamp (or your database equivalent), it is not stored in any format. When you query the column you would specify the format.

If it is stored as a varchar, you would want to use SimpleDateFormat to set your format. Then call stmt.setString() to use that format.

Needless to say, using a Date/Timestamp type in the database is recommended.


[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
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30789
    
157

I'm going to move this to our JDBC forum since it's more about database interaction.
Agador Paloi
Ranch Hand

Joined: Jan 24, 2006
Posts: 118
You dont have any control over the format the Timestamp is kept in the database. You can set the date time to what ever you want when you put it in of course . You can also control how you want to format it when you get a timestamp out of the database and display or print it somewhere.
 
wood burning stoves
 
subject: Date format