Use the datetime type to store the time in the MySQL database, use Resultset.gettimestamp () When reading this field in JDBC, and get a java.sql.Timestamp type of data. Neither resultset.getdate () nor resultset.gettime () can be used here, as the former does not include the time data, which does not include the date data.
However, it is not completely secure when using Resultset.gettimestamp (), for example, when a field value of type timestamp in a database is ' 0000-00-00 00:00:00 ', an exception is thrown when reading with this method: cannot Convert value ' 0000-00-00 00:00:00 ' from column 1 to TIMESTAMP, this is because JDBC cannot be ' 0000-00-00 00:00:00 ' Conversion to a java.sql.Timestamp, in Java, want to create a java.util.Date, so its value is ' 0000-00-00 ' is also impossible, the oldest date should be ' 0001-01-01 00:00:00 '.
Solution 1.String url = "jdbc:mysql://localhost:3306/test?relaxautocommit=true&zerodatetimebehavior= Converttonull";
Note that if the symbol "&" is unsuccessful, it needs to be converted to a specific character, as shown in the following table, which translates "&" to &
The following types of characters are escaped in the XML file:
< |
< |
Less than sign |
> |
> |
Greater than sign |
& |
& |
And |
' |
‘ |
Single quotation marks |
" |
" |
Double quotes |
Cannot convert value ' 0000-00-00 00:00:00 ' from column 1 to timestamp workaround