my dog learned polymorphism
The moose likes JDBC and Relational Databases and the fly likes Date format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Date format" Watch "Date format" New topic

Date format

Nick Davenport

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

Joined: May 26, 2003
Posts: 33129

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.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33129

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.
I agree. Here's the link:
subject: Date format
jQuery in Action, 3rd edition