Reference: JDBC setobject non-mainstream performance report [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 |
Attached SectionCode
calendar Cal = calendar. getinstance ();
timestamp now = New timestamp (Cal. gettime (). gettime ();
preparestatement is used for JDBC insertion. settimestamp ()
besides, preparestatement has a bunch of setint, setstring, Setdate or something. 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