何小豆儿在此 发表于 2024-6-11 03:08:42

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

https://img-blog.csdnimg.cn/direct/d50b1bc6c6db41438d9fdc9780c4e347.png
问题形貌:

当你使用 达梦数据库 创建数据表后,在项目中使用MyBatis-Plus实验插入数据到新建的表中时,有时步伐会报入如下错误
如下所示
https://img-blog.csdnimg.cn/direct/40c26a4bc2f448f0a4a5dc937d01a5eb.png#pic_center
完备报错信息如下
org.springframework.jdbc.UncategorizedSQLException: Error getting generated key or setting result to parameter object. Cause: java.sql.SQLException: Error
; uncategorized SQLException; SQL state ; error code ; Error; nested exception is java.sql.SQLException: Error
        at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:89) ~
        at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~
        at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~
        at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:88) ~
        at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:440) ~
        at com.sun.proxy.$Proxy108.insert(Unknown Source) ~
        at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:271) ~
        at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:60) ~
        at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:148) ~
        at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89) ~
        at com.sun.proxy.$Proxy166.insert(Unknown Source) ~
        at com.yxkj.jztb.task.cronTask.task1(cronTask.java:51) ~
        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.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65) ~
        at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) ~
        at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:93)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
        at java.util.concurrent.FutureTask.run(FutureTask.java)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.sql.SQLException: Error
        at com.alibaba.druid.pool.DruidDataSource.handleConnectionException(DruidDataSource.java:1652) ~
        at com.alibaba.druid.pool.DruidPooledConnection.handleException(DruidPooledConnection.java:133) ~
        at com.alibaba.druid.pool.DruidPooledStatement.checkException(DruidPooledStatement.java:82) ~
        at com.alibaba.druid.pool.DruidPooledStatement.getGeneratedKeys(DruidPooledStatement.java:842) ~
        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:78) ~
        at com.sun.proxy.$Proxy208.getGeneratedKeys(Unknown Source) ~
        at org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator.processBatch(Jdbc3KeyGenerator.java:79) ~
        at org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator.processAfter(Jdbc3KeyGenerator.java:71) ~
        at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:51) ~
        at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74) ~
        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.plugin.Plugin.invoke(Plugin.java:63) ~
        at com.sun.proxy.$Proxy206.update(Unknown Source) ~
        at com.baomidou.mybatisplus.core.executor.MybatisSimpleExecutor.doUpdate(MybatisSimpleExecutor.java:56) ~
        at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117) ~
        at com.baomidou.mybatisplus.core.executor.MybatisCachingExecutor.update(MybatisCachingExecutor.java:85) ~
        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.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:426) ~
        ... 22 common frames omitted
Caused by: java.lang.NullPointerException: null
        at dm.jdbc.driver.DmdbPreparedStatement.do_getGeneratedKeys(DmdbPreparedStatement.java:578) ~
        at dm.jdbc.driver.DmdbStatement.getGeneratedKeys(DmdbStatement.java:1433) ~
        at com.alibaba.druid.pool.DruidPooledStatement.getGeneratedKeys(DruidPooledStatement.java:834) ~
        ... 48 common frames omitted
原因分析:

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


[*]执行插入语句后获取天生键时出错(通常与自动递增主键或序列天生器相关)
[*]将查询或存储过程调用的结果设置到参数对象中时出错(例如,使用带有输出参数的 CallableStatement)
显然,MyBatis-Plus插入数据时获取生城建时出错了,那为何会出错?明明我新建表时设置了主键
https://img-blog.csdnimg.cn/direct/bd957f7f26794b839d79489b8fd98d46.png
等等,我貌似没有设置该主键字段ID为自增!!!
https://img-blog.csdnimg.cn/direct/117c5d28a9034633976b1e86d3ed79c0.png
我的潜意识里好像一直认为设置某字段为主键时,那么它会默认为自增,其实是错误的
https://img-blog.csdnimg.cn/direct/265ac7423ab14f0e829c167563486f7e.png
办理方案:

   将要设置自增属性的字段的自增属性打开即可!!!
这里以主键字段ID设为自增为例
达梦数据库DM管理工具操纵如下
https://img-blog.csdnimg.cn/direct/383d715e61e6422fa35aec388cea0813.png
https://img-blog.csdnimg.cn/direct/39dae0ffd8c8428c923465f265a8bec8.png

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: 办理org.springframework.jdbc.UncategorizedSQLException: Error getting