org.springframework.dao.DataIntegrityViolationException:

Error updating database. Cause: java.sql.SQLException: Field ‘id’ doesn’t have a default value

The error may exist in com/spring_trans/dao/SaleDao.xml

The error may involve defaultParameterMap

The error occurred while setting parameters

SQL: insert into sale(gid,nums) values(?,?)

Cause: java.sql.SQLException: Field ‘id’ doesn’t have a default value

; Field ‘id’ doesn’t have a default value; nested exception is java.sql.SQLException: Field ‘id’ doesn’t have a default value

at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:247)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
at com.sun.proxy.$Proxy6.insert(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:278)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:62)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:58)
at com.sun.proxy.$Proxy7.insertSale(Unknown Source)
at com.spring_trans.service.impl.BuyGoodsServiceImpl.buy(BuyGoodsServiceImpl.java:24)
at com.spring_trans.MyTest.test01(MyTest.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

Caused by: java.sql.SQLException: Field ‘id’ doesn’t have a default value
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3558)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3490)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2109)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2643)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2077)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1356)
at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:498)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:59)
at com.sun.proxy.Proxy11.execute(UnknownSource)atorg.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:47)atorg.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74)atorg.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:50)atorg.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)atorg.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)atorg.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:197)atorg.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:184)atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)atjava.lang.reflect.Method.invoke(Method.java:498)atorg.mybatis.spring.SqlSessionTemplateProxy11.execute(Unknown Source) at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:47) at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74) at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:50) at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117) at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76) at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:197) at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:184) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.mybatis.spring.SqlSessionTemplateProxy11.execute(UnknownSource)atorg.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:47)atorg.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74)atorg.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:50)atorg.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)atorg.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)atorg.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:197)atorg.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:184)atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)atjava.lang.reflect.Method.invoke(Method.java:498)atorg.mybatis.spring.SqlSessionTemplateSqlSessionInterceptor.invoke(SqlSessionTemplate.java:433)
… 29 more

解决方案:
打开数据库操作软件,找到报错对应的数据库表,将主键id设置为自动递增,然后保存即可

Cause: java.sql.SQLException: Field ‘id‘ doesn‘t have a default value相关推荐

  1. 解决:Cause: java.sql.SQLException: Field ‘id‘ doesn‘t have a default value

    解决:Cause: java.sql.SQLException: Field 'id' doesn't have a default value; nested exception is java.s ...

  2. 如何解决Cause: java.sql.SQLException: Field ‘id‘ doesn‘t have a default value

    在做商品上传功能的时候报了Cause: java.sql.SQLException: Field 'id' doesn't have a default value的错误(主要错误如下),经查询是因为 ...

  3. 解决java.sql.SQLException: Field ‘id‘ doesn‘t have a default value问题

    问题截图: 问题描述: java.sql.SQLException: Field 'id' doesn't have a default value(字段id没有默认值) 原因: 自己的MySQL数据 ...

  4. java.sql.SQLException: Field ‘id‘ doesn‘t have a default value

    前言 最近向数据库中保存数据时报错 错误代码如下: Field 'id' doesn't have a default value; nested exception is java.sql.SQLE ...

  5. java.sql.SQLException: Field 'id' doesn't have a default value解决方案

    转自:https://blog.csdn.net/xinghuo0007/article/details/51810867 自增长:java.sql.SQLException: Field 'id' ...

  6. Java java.sql.SQLException: Field ‘xxx‘ doesn‘t have a default value

    问题描述: Caused by: java.sql.SQLException: Field 'username' doesn't have a default value 问题分析: 1.数据库表字段 ...

  7. java.sql.SQLException: Field ‘habit_id‘ doesn‘t have a default value

    bug 记录,今天执行下面这段代码时报:java.sql.SQLException: Field 'habit_id' doesn't have a default value异常 String sq ...

  8. java.sql.SQLException: Field 'Qid' doesn't have a default value

    java.sql.SQLException: Field 'Qid' doesn't have a default value错误 在网上查了很多资料,要不是不相同,要不就是看着特别复杂,最后翻书发现 ...

  9. Field ‘gmt_create‘ doesn‘t have a default value; nested exception is java.sql.SQLException: Field ‘g

    涉及技术: SpringBoot 测试出错: IDEA 添加数据时出错 org.springframework.dao.DataIntegrityViolationException: ### Err ...

最新文章

  1. SQLServer代理新建或者编辑作业报错
  2. Emscripten 单词_初一(上)掌握这 4 大类发音规律,英语记单词很轻松
  3. Office Web Apps所需证书的申请分配部署详解
  4. asp.net 返回表单json数据 辅助类
  5. ubuntu下从软件中心安装软件时的软件缓存目录
  6. 九、面向对象三大特征(三)—— 多态
  7. (转)用Javascript获取页面元素的位置
  8. java fp-growth 算法包_java实现fp-growth算法
  9. visio2016 数据库模型图_数据库相关术语整理
  10. C语言有某程序入口,C语言入门 — 程序入口
  11. 李开复给中国学生的四封信(转载)
  12. 计算机的进制的转换公式,计算机进制转换公式
  13. import xx fromxx 的含义
  14. [论文笔记] Balboa: Bobbing and Weaving around Network Censorship
  15. 2019年暑期GooGle SWE 凉经
  16. IDEA安装及配置jdk
  17. Tarena - 分组查询
  18. 某游戏公司(凯英网络)PHP开发工程师笔试题
  19. IPV6 IPV4 java 转换为数字
  20. 闽高校计算机二级c语言模拟器,闽高校计算机二级C语言模拟题

热门文章

  1. 如果我有一颗私人卫星……|潮科技有奖问答评论精选 ②
  2. 浙大PAT考试1013~1016(最伤的一次。。)
  3. 搭建一套基于 Groovy 规则引擎的业务风控平台
  4. Oracle中 to_date()函数用法详解
  5. 符号“∑”和“Π”的用法。
  6. window浏览器被劫持如何修复,hao123,2345 等
  7. 最小生成树模板 POJ——1258
  8. H3C服务器修改启动项,H3C服务器 iFIST快速安装指南-6W102
  9. html中td内容不换行显示,html小技巧之td,div标签里内容不换行
  10. tf.estimator.Estimator解析