Problem with updating oracle DB with java date thru resultset.updateDate()

URGENT Please

I am facing problem in updating oracle database with java date through resultset.updateDate() method. Can anybody help me please

following code is saving wrong date value (dec 4, 2006 instead of java date jul 4, 2007) in database:

ResultSet rs = stmt.executeQuery("SELECT myDate FROM myTable");

rs.first();

SimpleDateFormat sqlFormat =new SimpleDateFormat("yyyy-mm-dd");

java.util.Date myDate =new Date();

rs.updateDate("myDate", java.sql.Date.valueOf(sqlFormat.format(myDate)));

rs.updateRow();

[714 byte] By [W-Sa] at [2007-11-27 9:35:08]
# 1

I believe you should use yyyy-MM-dd instead of yyyy-mm-dd. I think MM stands for month while mm stands for minute as per

http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html

(If this works, after spending so much of your time trying to solve it, don't hit yourself in the head too hard. I find running out of the room laughing hysterically feels better).

Here is a more standard(?) way of updating:

String sqlStatement=

"update myTable set myDate=? where personID=?"

PreparedStatement p1= connection.prepareStatement(sqlStatement);

p1.setDate(1,new java.sqlDate());

p1.setInt(2, personID);

p1.executeUpdate();

George123a at 2007-7-12 23:01:24 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

yes, you are right updating with prepared statement is a better way but i have to use unprepared statement due to some inevitable reasons.

It is requirement of .value() mathod of java.sql.Date class to set date in the format yyyy-mm-dd and in our case this is working correct. but problem is after that when we get date in the arguments fo updateDate method. as java.sql.Date returns date string in a fixed format that is yyyyy-mm-dd that is appropriate for all db servers except oracle (i think) that requires in dd-MMM-yyyy.

Is there any way to configure Oracle server so that it accept date in yyyy-mm-dd format?

W-Sa at 2007-7-12 23:01:24 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
The only other idea I have is to preceed single digit numbers with zero in the dd-mm-yyyyExample: instead of 1-3-2007 use 01-03-2007. If that doesn't work, I'm out of ideas.
George123a at 2007-7-12 23:01:24 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...