办理org.springframework.jdbc.UncategorizedSQLException: Error getting ...

打印 上一主题 下一主题

主题 951|帖子 951|积分 2853




问题形貌:

当你使用 达梦数据库 创建数据表后,在项目中使用MyBatis-Plus实验插入数据到新建的表中时,有时步伐会报入如下错误
如下所示

完备报错信息如下
  1. org.springframework.jdbc.UncategorizedSQLException: Error getting generated key or setting result to parameter object. Cause: java.sql.SQLException: Error
  2. ; uncategorized SQLException; SQL state [null]; error code [0]; Error; nested exception is java.sql.SQLException: Error
  3.         at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:89) ~[spring-jdbc-5.0.7.RELEASE.jar:5.0.7.RELEASE]
  4.         at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~[spring-jdbc-5.0.7.RELEASE.jar:5.0.7.RELEASE]
  5.         at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~[spring-jdbc-5.0.7.RELEASE.jar:5.0.7.RELEASE]
  6.         at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:88) ~[mybatis-spring-2.0.5.jar:2.0.5]
  7.         at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:440) ~[mybatis-spring-2.0.5.jar:2.0.5]
  8.         at com.sun.proxy.$Proxy108.insert(Unknown Source) ~[na:na]
  9.         at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:271) ~[mybatis-spring-2.0.5.jar:2.0.5]
  10.         at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:60) ~[mybatis-plus-core-3.4.1.jar:3.4.1]
  11.         at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:148) ~[mybatis-plus-core-3.4.1.jar:3.4.1]
  12.         at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89) ~[mybatis-plus-core-3.4.1.jar:3.4.1]
  13.         at com.sun.proxy.$Proxy166.insert(Unknown Source) ~[na:na]
  14.         at com.yxkj.jztb.task.cronTask.task1(cronTask.java:51) ~[classes/:na]
  15.         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
  16.         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161]
  17.         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161]
  18.         at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161]
  19.         at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
  20.         at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
  21.         at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:93) [spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
  22.         at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_161]
  23.         at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266) [na:1.8.0_161]
  24.         at java.util.concurrent.FutureTask.run(FutureTask.java) [na:1.8.0_161]
  25.         at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_161]
  26.         at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.8.0_161]
  27.         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_161]
  28.         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_161]
  29.         at java.lang.Thread.run(Thread.java:748) [na:1.8.0_161]
  30. Caused by: java.sql.SQLException: Error
  31.         at com.alibaba.druid.pool.DruidDataSource.handleConnectionException(DruidDataSource.java:1652) ~[druid-1.1.16.jar:1.1.16]
  32.         at com.alibaba.druid.pool.DruidPooledConnection.handleException(DruidPooledConnection.java:133) ~[druid-1.1.16.jar:1.1.16]
  33.         at com.alibaba.druid.pool.DruidPooledStatement.checkException(DruidPooledStatement.java:82) ~[druid-1.1.16.jar:1.1.16]
  34.         at com.alibaba.druid.pool.DruidPooledStatement.getGeneratedKeys(DruidPooledStatement.java:842) ~[druid-1.1.16.jar:1.1.16]
  35.         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
  36.         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161]
  37.         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161]
  38.         at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161]
  39.         at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:78) ~[mybatis-3.5.6.jar:3.5.6]
  40.         at com.sun.proxy.$Proxy208.getGeneratedKeys(Unknown Source) ~[na:na]
  41.         at org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator.processBatch(Jdbc3KeyGenerator.java:79) ~[mybatis-3.5.6.jar:3.5.6]
  42.         at org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator.processAfter(Jdbc3KeyGenerator.java:71) ~[mybatis-3.5.6.jar:3.5.6]
  43.         at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:51) ~[mybatis-3.5.6.jar:3.5.6]
  44.         at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74) ~[mybatis-3.5.6.jar:3.5.6]
  45.         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
  46.         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161]
  47.         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161]
  48.         at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161]
  49.         at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:63) ~[mybatis-3.5.6.jar:3.5.6]
  50.         at com.sun.proxy.$Proxy206.update(Unknown Source) ~[na:na]
  51.         at com.baomidou.mybatisplus.core.executor.MybatisSimpleExecutor.doUpdate(MybatisSimpleExecutor.java:56) ~[mybatis-plus-core-3.4.1.jar:3.4.1]
  52.         at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117) ~[mybatis-3.5.6.jar:3.5.6]
  53.         at com.baomidou.mybatisplus.core.executor.MybatisCachingExecutor.update(MybatisCachingExecutor.java:85) ~[mybatis-plus-core-3.4.1.jar:3.4.1]
  54.         at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:197) ~[mybatis-3.5.6.jar:3.5.6]
  55.         at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:184) ~[mybatis-3.5.6.jar:3.5.6]
  56.         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
  57.         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161]
  58.         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161]
  59.         at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161]
  60.         at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:426) ~[mybatis-spring-2.0.5.jar:2.0.5]
  61.         ... 22 common frames omitted
  62. Caused by: java.lang.NullPointerException: null
  63.         at dm.jdbc.driver.DmdbPreparedStatement.do_getGeneratedKeys(DmdbPreparedStatement.java:578) ~[DmJdbcDriver18.jar:- 8.1.1.134 - Production]
  64.         at dm.jdbc.driver.DmdbStatement.getGeneratedKeys(DmdbStatement.java:1433) ~[DmJdbcDriver18.jar:- 8.1.1.134 - Production]
  65.         at com.alibaba.druid.pool.DruidPooledStatement.getGeneratedKeys(DruidPooledStatement.java:834) ~[druid-1.1.16.jar:1.1.16]
  66.         ... 48 common frames omitted
复制代码

原因分析:

Error getting generated key or setting result to parameter object:该信息通常表明存在以下问题之一:


  • 执行插入语句后获取天生键时出错(通常与自动递增主键或序列天生器相关)
  • 将查询或存储过程调用的结果设置到参数对象中时出错(例如,使用带有输出参数的 CallableStatement)
显然,MyBatis-Plus插入数据时获取生城建时出错了,那为何会出错?明明我新建表时设置了主键

等等,我貌似没有设置该主键字段ID为自增!!!

我的潜意识里好像一直认为设置某字段为主键时,那么它会默认为自增,其实是错误的


办理方案:

   将要设置自增属性的字段的自增属性打开即可!!!
  这里以主键字段ID设为自增为例
达梦数据库DM管理工具操纵如下




免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

何小豆儿在此

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表