How to convert java.util.date into java.sql.date?

xiaoxiao2021-03-05  25

How to convert java.util.date into java.sql.date?

Transformation:

Java.sql.date sd;

Java.util.date UD;

// Initialize The Ud Such as ud = new java.util.date ();

SD = new java.sql.date (ud.gettime ());

If you want to insert into the database and the corresponding field is a Date type

Then you can use PreparedStatement.SetDate (int, java.sql.date)

Where java.sql.date can be obtained with the above method

You can also provide to_date functions with a database.

For example, existing UD

To_date (New SimpleDateFormat (). Format (UD, "YYYY-MM-DD HH: MM: SS"),

"YYYY-MM-DD HH24: MI: SS")

Note that the formats provided by the format and databases in Java are different.

转载请注明原文地址:https://www.9cbs.com/read-33977.html

New Post(0)