Value ' 0000-00-00 ' can not represented as Java.sql.Datetime 2014-07-30 09:00:50 iteye-Blog
Originalhttp://josh-persistence.iteye.com/blog/2098415 ThemesJava SQL
Java.sql.SQLException:Value ' 0000-00-00 00:00:00 ' can not is represented as Java.sql.Timestamp
problem description, in a Java application, the data table has a record time field (property of timestamp) whose value is: "0000-00-00 00:00:00"
The following exception occurs when a program uses the SELECT statement to fetch data from:
Java.sql.SQLException:Value ' 0000-00-00 ' can not is represented as Java.sql.Date
This is because "0000-00-00 00:00:00" exists as a special value in MySQL, but in Java, Java.sql.Date is considered an illegal value and is considered malformed by the JVM.
Workaround:
Add the Zerodatetimebehavior parameter to the JDBC URL:
DATASOURCE.URL=JDBC:MYSQL://LOCALHOST:3306/PE?USEUNICODE=TRUE&CHARACTERENCODING=GBK & Zerodatetimebehavior=converttonull
For records with a value of 0000-00-00 00:00:00 (the default), different results are returned depending on the configuration:
Not configured: Default return exception
Zerodatetimebehavior=round 0001-01-01 00:00:00.0
Zerodatetimebehavior=converttonull NULL
But it is possible to report a new exception:
The reference to entity "characterencoding" must end with the '; ' delimiter
This may be due to forgetting to translate special symbols in the properties file or in an XML file.
Jdbc:mysql://192.168.1.155:3306/diandi?useunicode=true&characterencoding=utf-8 & Zerodatetimebehavior=converttonull
Need to read:
Jdbc:mysql://192.168.1.155:3306/diandi?useunicode=true&characterencoding=utf-8 & Zerodatetimebehavior=converttonull
There are several types of characters to be escaped and replaced:
< |
< |
Less than sign |
> |
> |
Greater than sign |
& |
& |
And |
' |
‘ |
Single quotation marks |
" |
" |
Double quotes |
Value ' 0000-00-00 ' can not represented as java.sql.Date