Data truncation: Out of range value

时间:2024-05-19 19:54:59

遇到一个奇怪的错误

com.mysql.jdbc.MysqlDataTruncation: Data truncation: Out of range value for column 'userId' at row 1
	com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3374)
	com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3308)
	com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1837)
	com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1961)
	com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2543)
	com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1737)
	com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2022)
	com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1940)
	com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1925)
	org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
	org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)

 

然后追溯到sql语句

Sql代码  Data truncation: Out of range value
  1. insert   
  2.         into  
  3.             t_access_log  
  4.             (access_day, access_daytime, access_type, description, device_id, device_type, extranet_ip,   
  5. ip, operate_result, os_type, query_string, request_target, requestURI, reserved, session2_id, time, user_agent, userId, username)   
  6.         values  
  7.             ('2016-03-18''2016-03-18 20:23:03''1''手机端视频列表'nullnull'127.0.0.1''127.0.0.1',  
  8.  '总条数:756'nullnull'video:json''/video/json'NULL'E065035A48A191F7DA5BA312E0112705', 1458303783,   
  9. 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36', -1, null);  

 执行结果:

[SQL]insert 

        into

            t_access_log

            (access_day, access_daytime, access_type, description, device_id, device_type, extranet_ip, 

ip, operate_result, os_type, query_string, request_target, requestURI, reserved, session2_id, time, user_agent, userId, username) 

        values

            ('2016-03-18', '2016-03-18 20:23:03', '1', '手机端视频列表', null, null, '127.0.0.1', '127.0.0.1',

 '总条数:756', null, null, 'video:json', '/video/json', NULL, 'E065035A48A191F7DA5BA312E0112705', 1458303783, 

'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36', -1, null);

[Err] 1264 - Out of range value for column 'userId' at row 1

 

看看userId的类型,终于找到了原因
Data truncation: Out of range value
 

userId的类型是正整数,所以报错了