When you recently imported data from MySQL, you found that some records could not be imported. The reason is that the 0000-00-00 00:00:00 time format could not be converted, the online search, in this way can solve the problem.
Using the datetime type in the MySQL database to store the time, you should use Resultset.gettimestamp () When reading this field in JDBC, which will get a java.sql.Timestamp type of data. Neither resultset.getdate () nor resultset.gettime () can be used here because the former does not include time data and the latter does not include date data.
However, it is not completely secure when using Resultset.gettimestamp (), for example, when a timestamp type in a database has a field value of ' 0000-00-00 00:00:00 ', an exception is thrown when the method is used for reading: cannot Convert value ' 0000-00-00 00:00:00 ' from column 1 to TIMESTAMP because JDBC cannot convert ' 0000-00-00 00:00:00 ' to a java.sql. Timestamp, in Java, it is impossible to create a java.util.Date value of ' 0000-00-00 ', 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 converts "&" to &
There are several types of characters in the XML file that you want to escape from:
< |
< |
Less than sign |
> |
> |
Greater-than sign |
& |
& |
And |
' |
' |
Single quotation mark |
" |
" |
Double quotes |