700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > Cause: java.sql.SQLException: Field ‘id‘ doesn‘t have a default value

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

时间:2018-08-24 09:32:43

相关推荐

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

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设置为自动递增,然后保存即可

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。