The following information will help you
1. Convert Java.util.Date to Java.sql.Date
Java.util.Date utildate = new Java.util.Date ();
Java.sql.Date sqldate = new Java.sql.Date (Utildate.gettime ());
2. To insert into the database and the corresponding field is of the date type
You can use the preparedstatement.setdate (int, java.sql.Date) method
The java.sql.Date can be obtained using the above method
You can also use the database to provide to_date functions
such as existing UD
To_date (New SimpleDateFormat (). Format (UD, "Yyyy-mm-dd HH:mm:ss"),
"Yyyy-mm-dd HH24:MI:SS")
Note that in Java, the format differs from the format provided by the database
Sql= "UPDATE tablename set Timer=to_date ('" +x+ "', ' Yyyymmddhh24miss ') where ..."
The x here is similar to the variable: 20080522131223
3. How to convert a string in "YYYY-MM-DD" format to Java.sql.Date
Method 1
Simpledateformatbartdateformat = new SimpleDateFormat ("Yyyy-mm-dd");
Stringdatestringtoparse= "2007-7-12";
try{
Java.util.datedate= Bartdateformat.parse (Datestringtoparse);
java.sql.datesqldate= New Java.sql.Date (Date.gettime ());
System.out.println (Sqldate.gettime ());
}
catch (Exception ex) {
System.out.println (Ex.getmessage ());
}
How to convert Java.util.Date to Java.sql.Date