Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Convert Calendar to Java.sql.Date

807603Jun 27 2005 — edited Nov 13 2007
I seached for a solution for converting a Calendar-object to a java.sql.date for inserting it into a MySQL DB (DateTime). I know this question is a FAQ. The solution I found is the following code:
java.sql.Date sqlDate =  new java.sql.Date(cal.getTime().getTime() );
When i do a print of the sqlDate to the console I get: sqlDate: 2005-06-27
But when I look into de DB I get the following date: 27/05/1905
I know that in Java the months are starting from 0-�11 and that the years counting is starting from 1900. But I assume that the solution is not to just add the correct month and year manually. because I get a correct console-output. If I do this I get a correct DB Date, but a wrong console-date.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 11 2007
Added on Jun 27 2005
16 comments
10,025 views