zoukankan      html  css  js  c++  java
  • Mysql 升级到 5.6 后插入语句时间字段报错:Incorrect datetime value: '' for column 'createtime'

    今天部署服务器项目运行,当遇见有时间数据对象的插入和更新操作的时候,就报错,如下:

    Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: '' for column 'createtime' at row 1 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2868) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573) at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1160) at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:685) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1400) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1314) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1299) at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105) at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105) at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:94) at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:57) ... 109 more  

    在MySQL版本问题上,我在测试上用的是5.1版本,服务器上使用的是最新的5.6版本;看到网上说5.6对时间类型做了调整,于是果断换成5.5的Mysql64位。测试,通过,正常。

    所以,遇见该问题解决方法,目前是换数据库版本,因为是5.6版本比较新。

    解决方法如下:

    找到你项目中的mysql-connector-java的jar包

    将此更新到最新版本,我目前项目使用的环境是:java7,

    更新使用的jar包是:mysql-connector-java-5.1.31.jar

    经过我的测试没有问题。

    如果你的环境是java6,这个jar也是可以的。

    完成

  • 相关阅读:
    A. Dawid and Bags of Candies ( Codeforces Round #588 (Div. 2) )
    B. Ania and Minimizing (Codeforces Round #588 (Div. 2) )
    残缺的棋盘 (BFS)
    Max Sum (动态规划)
    高桥和低桥 (离散化 )
    White Sheet (矩形面积模板) (Codeforces Round #587 (Div. 3) )
    Catch That Cow (BFS luo搜 + 剪枝)
    Python笔记-字符串
    关于拖延症
    一些告诫
  • 原文地址:https://www.cnblogs.com/zuge/p/5822786.html
Copyright © 2011-2022 走看看