This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes storing dates using prepared statements Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "storing dates using prepared statements" Watch "storing dates using prepared statements" New topic
Author

storing dates using prepared statements

prav ba
Greenhorn

Joined: Jun 17, 2007
Posts: 12
hi all,
have got a method which converts java.util.Date to java.sql.Date and stores it to oracle 11g db.




the problem is that when i look into the db the value stored is 05-05-0005 which is not correct since i would have thought the value stored would be 05-05-2005.

can anyone explain why this is happening ??

thanks.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

This is nothing to do with JDBC at all. You simply have misunderstood SimpleDateFormat. Direct quote from its API documentation:
For parsing, if the number of pattern letters is more than 2, the year is interpreted literally, regardless of the number of digits. So using the pattern "MM/dd/yyyy", "01/11/12" parses to Jan 11, 12 A.D.
prav ba
Greenhorn

Joined: Jun 17, 2007
Posts: 12
aha !! thanks Paul.
 
jQuery in Action, 2nd edition
 
subject: storing dates using prepared statements
 
Similar Threads
Question on ParseException
SQLException caught: ORA-17041: (no message for error) 1
date problem
date format problem
problem insering date value in database