CREATE TABLE `test` (
`test` datetime NOT NULL default '0000-00-00 00:00:00'
) TYPE=MyISAM;
插入记录
INSERT INTO `test` ( `t1` )
VALUES (
'0000-00-00 00:00:00'
)
检索
select * from test
使用jdbc
Error Executing: select * from test:java.sql.SQLException: Cannot convert value
'0000-00-00 00:00:00' from column 1 to TIMESTAMP.
java.sql.SQLException: Cannot convert value '0000-00-00 00:00:00' from column 1 to
TIMESTAMP.
at com.mysql.jdbc.ResultSet.getTimestampFromString(ResultSet.java:5712)
at com.mysql.jdbc.ResultSet.getTimestampInternal(ResultSet.java:5740)
at com.mysql.jdbc.ResultSet.getTimestamp(ResultSet.java:5393)
at sun.reflect.GeneratedMethodAccessor8.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
处理 jdbc:mysql://localhost:3306/mydbname?zeroDateTimeBehavior=convertToNull
原因很简单,'0000-00-00 ...' java无法处理,只好将它转为null。