MySQL JDBC data type Reference: non-mainstream performance report of JDBC setObject [1]
The time type in MySQL and JAVA corresponds
MYSQL time type |
Time type corresponding to JAVA |
Date |
Java. SQL. Date |
Year |
Ava. SQL. Date |
Datetime |
Java. SQL. Timestamp |
Timestamp |
Java. SQL. Timestamp |
Time |
Java. SQL. Time |
Attach a piece of code
Calendar cal=Calendar.getInstance();
Timestamp now=new Timestamp(cal.getTime().getTime());
Then prepareStatement. setTimestamp () is used for JDBC insertion ()
Let's talk about prepareStatement. There are a bunch of setInt, setString, setDate and so on. In fact, there is also a very powerful stObject () that can automatically convert the matching type, and the performance is not bad, which extends a lot of usage, in fact, I just used to insert null-_-to the preparedStatement -_-! In addition, if you leave the placeholder in preparedStatement empty, it will be written as ** not specified **. I don't know if it will be automatically converted to null.