银点 2018年05月07日
spring boot mybatis向mysql插数据的问题
1、数据库是mysql 5.7
2、字符串默认是utf8
3、IDE是为idea 2017
简单的增删改查

CREATE TABLE `user` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(16) NOT NULL,
`phone` varchar(11) NOT NULL,
`sex` int(11) NOT NULL DEFAULT '-1',
`role` int(11) DEFAULT '0' ,
`passwd` varchar(32) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;



public class User {
private Integer userId;
private String userName;
private String userPassword;
private String userPhone;
private Integer userSex;
private Integer userRole;
……
}

我在mysql客户端工具中直接写sql语句insert 的时候11位手机号是能写进去的。
但是在程序中一执行就报phone超长了。

2018-05-07 15:55:59.177 DEBUG 12912 --- [nio-8080-exec-5] c.s.dinner.mapper.UserMapper.createUser : ==> Preparing: insert into user(name,passwd, phone,sex)values(?,?,?,?)
2018-05-07 15:55:59.177 DEBUG 12912 --- [nio-8080-exec-5] c.s.dinner.mapper.UserMapper.createUser : ==> Parameters: 'test'(String), '123456'(String), '18516693703'(String), 1(Integer)
2018-05-07 15:55:59.193 ERROR 12912 --- [nio-8080-exec-5] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException:
### Error updating database. Cause: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'phone' at row 1
### The error may involve com.senxiang.dinner.mapper.UserMapper.createUser-Inline
### The error occurred while setting parameters
### SQL: insert into user(name,passwd, phone,sex)values(?,?,?,?)
### Cause: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'phone' at row 1
; ]; Data truncation: Data too long for column 'phone' at row 1; nested exception is com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'phone' at row 1] with root cause
...全文
802 点赞 收藏 2
写回复
2 条回复

还没有回复,快来抢沙发~

发动态
发帖子
Web 开发
创建于2007-09-28

5.2w+

社区成员

34.1w+

社区内容

Java Web 开发
社区公告
暂无公告