Java.preparedStatement.SetTimeStamp () Save the date type with java.sql.timestamp

xiaoxiao2021-03-06  61

The save date includes time seconds, you want to use java.preparedState .SetTimeSTAMP ().

If the date is a string type first conversion to a date type, then transform into a TimeStamp type, save it.

Code:

Import java.sql. *;

...

CONNECTION CONN = ....

Connection conn = NULL;

String mydate = "2004-12-12 12:12:12";

Java.text.SIMPLEDATEFORMAT SDF = New Java.Text.SIMPLEDATEFORMAT ("YYYY-MM-DD HH: MM: SS");

PREPAREDSTATEMENT PS = Conn.PrepareStatement ("INSERT INTO TABLE TESTDATE VLAUES?");

Ps.setTimeStamp (SDF.PARSE (MyDate));

ps.execute ()

...

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

New Post(0)