今天敲代码的时候碰到了一个bug
"\r\n### Error updating database. Cause: java.sql.SQLIntegrityConstraintViolationException: Column 'title' cannot be null\r\n### The error may exist in worldtolingyidianke/file/mappers/ContentMapper.java (best guess)\r\n### The error may involve worldtolingyidianke.file.mappers.ContentMapper.add-Inline\r\n### The error occurred while setting parameters\r\n### SQL: insert into content(title,content) values(?,?)\r\n### Cause: java.sql.SQLIntegrityConstraintViolationException: Column 'title' cannot be null\n; Column 'title' cannot be null; nested exception is java.sql.SQLIntegrityConstraintViolationException: Column 'title' cannot be null",
意思是
“\r\n###更新数据库时出错。原因:Java . SQL . sqlintegrityconstraintviolationexception:列“title”不能为空\r\n###错误可能存在于worldtolingyidiank/file/mappers/content mapper . Java中(最佳猜测)\r\n###错误可能涉及worldtolingyidiank . file . mappers . content mapper . add-Inline \ r \ n # # #设置参数时出错\ r \ n # # # SQL:insert into content(title,content)值(?,?)\r\n###原因:Java . SQL . sqlintegrityconstraintviolationexception:列“title”不能为空\ n;列“title”不能为空;嵌套异常为Java . SQL . sqlintegrityconstraintviolationexception:列“title”不能为空
这里的错误,他说可能存在于worldtolingyidiank/file/mappers/content.mapper
“\r\n###更新数据库时出错。原因:Java . SQL . sqlintegrityconstraintviolationexception:列“title”不能为空\r\n###错误可能存在于worldtolingyidiank/file/mappers/content mapper . Java中(最佳猜测)\r\n###错误可能涉及worldtolingyidiank . file . mappers . content mapper . add-Inline \ r \ n # # #设置参数时出错\ r \ n # # # SQL:insert into content(title,content)值(?,?)\r\n###原因:Java . SQL . sqlintegrityconstraintviolationexception:列“title”不能为空\ n;列“title”不能为空;嵌套异常为Java . SQL . sqlintegrityconstraintviolationexception:列“title”不能为空
id不能为空,之前自己写数据的时候,没有添加自动添加的那个字段,可能是因为这个原因
重新建一下表:
create table content( id int primary key auto_increment, title varchar(255), content text )charset utf8;