Mysql 升級到 5.6 後插入語句時間欄位報錯:Incorrect datetime value: '' for column 'createtime'

來源:互聯網
上載者:User

標籤:

今天部署伺服器項目運行,當遇見有時間資料對象的插入和更新操作的時候,就報錯,如下:

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也是可以的。

完成

Mysql 升級到 5.6 後插入語句時間欄位報錯:Incorrect datetime value: '' for column 'createtime'

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.