Caused by: java.sql.SQLException: Field 'id' doesn't have a default value

 

hibernate 插入数据错误:Caused by: java.sql.SQLException: Field 'id' doesn't have a default value

无法插入数据;

 

错误原因: id在数据库表中是作为主键,但是在插入的过程中,没有给予数值,并且没有让其自增

 

解决办法: 修改数据库表中的id,让其自增(在插入的过程中,不插入id数据时

例如这样创建表:

CREATE TABLE books(id INT PRIMARY KEY auto_increment,Bookname VARCHAR(50),Bookprice VARCHAR(40));

posted @ 2018-05-19 22:42  zhaocundang  阅读(1541)  评论(0编辑  收藏  举报