设为首页收藏本站

Discuz! Board

 找回密码
 注-册

QQ登录

只需一步,快速开始

搜索
查看: 29372|回复: 1

Cannot convert value '0000-00-00 00:00:00' from column [N] to TIMESTAMP

[复制链接]
发表于 2007-1-5 01:31:28 | 显示全部楼层 |阅读模式
error:
java.sql.SQLException: Cannot convert value '0000-00-00 00:00:00' from column 20 to TIMESTAMP.

solve:
连接数据库的url增加:zeroDateTimeBehavior=convertToNull 或 round

解决方案参考:
http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configuration-properties.html
http://bugs.mysql.com/bug.php?id=18308
Maybe the problem is with connection string. It should include zeroDateTimeBehavior=convertToNull.
con=DriverManager.getConnection("jdbc:mysql://localhost/test?zeroDateTimeBehavior=convertToNull","root","");
 楼主| 发表于 2009-10-10 21:13:18 | 显示全部楼层
• Datetimes with all-zero components (0000-00-00 ...)— These values can not be
represented reliably in Java. Connector/J 3.0.x always converted them to NULL when being
read from a ResultSet.
Connector/J 3.1 throws an exception by default when these values are encountered as this
is the most correct behavior according to the JDBC and SQL standards. This behavior can be
modified using the zeroDateTimeBehavior configuration property.
The allowable values are:
• exception (the default), which throws an SQLException with an SQLState of S1009.
• convertToNull, which returns NULL instead of the date.
• round, which rounds the date to the nearest closest value which is 0001-01-01.
Starting with Connector/J 3.1.7, ResultSet.getString() can be decoupled from this behavior
via noDatetimeString-Sync=true (the default value is false) so that you can get retrieve
the unaltered all-zero value as a String. It should be noted that this also precludes
using any time zone conversions, therefore the driver will not allow you to enable
noDatetimeString-Sync and useTimezone at the same time.
您需要登录后才可以回帖 登录 | 注-册

本版积分规则

小黑屋|手机版|Archiver|数码鹭岛 ( 闽ICP备05008334号 )  

counter

GMT+8, 2018-2-22 22:01 , Processed in 0.145383 second(s), 24 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表