This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes JDBC and the fly likes insert and get date in postgresql Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "insert and get date in postgresql" Watch "insert and get date in postgresql" New topic
Author

insert and get date in postgresql

hani Ibrahim
Ranch Hand

Joined: Sep 06, 2006
Posts: 182
dear all,
im so weak with type Date .so i dont know how to make Date in format:
mm/dd//yyyy from java to get Date from PC then insert it in a table with column of type date.
please give me how to make this to insert date in db..and also how to get date from a column then convert it to java style .
please help
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30586
    
154

Hani,
Take a look at the SimpleDateFormat class. it lets you convert from String to Date and back. Then you can use a PreparedStatement's setDate() method and ResultSet's getDate() method to talk to the database with a date object.


[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
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

And, SimpleDateFormat produces a java.util.Date object but JDBC works with java.sql.Date objects. Fortunately it's easy to create a java.sql.Date object from a java.util.Date object, just check its list of constructors.
 
GeeCON Prague 2014
 
subject: insert and get date in postgresql