使用Oracle 11g时,保存数据时SQLException: 调用中的无效参数

  1. 背景与问题描述:

  2. 项目环境:jfinal:3.5,druid:1.0.29,oracle11g 驱动:ojdbc6.jar
    项目开发完成时切换到Oracle 11g数据库时,某张表save的时候发生SQL异常,奇怪的是同一个映射文件中的其他表插入时没有问题.(H表有问题,Zrz表没有问题)

  3. 异常发生点:
    Model类的523行,异常详情附在最后.
    image.png

  4. 调查思路:
    初步怀疑是H表的主键或字段有特殊性,经调查,与Zrz一致,排除这种可能
    然后怀疑是我们自行封装的框架bug,然后移除我们对框架修改的痕迹,问题依旧
    尝试使用Db.save方法保存,问题依旧,而Zrz表无论是.save 还是db.save,都能毫无问题的插入,H表两种方法保存都报错,这就有意思了,开始怀疑是驱动和druid版本的问题,换最新版和其他版本,问题依旧,开始又怀疑是表的特殊性.后将表改名为Room,问题排除.

  5. 结论:
    oracle 11g 数据库,在表名只有一个字母时,会产生异常,建议表名带有统一前缀com.jfinal.plugin.activerecord.ActiveRecordException: java.sql.SQLException: 调用中的无效参数

  6. 扩展:
    虽然单字母表名在一般的项目中不太容易出现,但是不明白为什么会出现这种问题,是驱动的问题?jdbc连接的问题?还是activeRecord的问题?希望大神能点拨一下.

com.jfinal.plugin.activerecord.ActiveRecordException: java.sql.SQLException: 调用中的无效参数

at com.jfinal.plugin.activerecord.DbPro.save(DbPro.java:647)

at com.jfinal.plugin.activerecord.DbPro.save(DbPro.java:657)

at com.jfinal.plugin.activerecord.Db.save(Db.java:463)

at com.chris.zrz.ZrzService.importZrzFromCh(ZrzService.java:407)

at com.chris.zrz.ZrzController.importZrzFromCh(ZrzController.java:122)

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 com.jfinal.aop.Invocation.invoke(Invocation.java:75)

at com.majian.framework.common.interceptor.EhCacheInterceptor.intercept(EhCacheInterceptor.java:22)

at com.jfinal.aop.Invocation.invoke(Invocation.java:69)

at com.majian.framework.common.interceptor.AuthInterceptor.intercept(AuthInterceptor.java:27)

at com.jfinal.aop.Invocation.invoke(Invocation.java:69)

at com.majian.framework.common.interceptor.UserInfoInterceptor.intercept(UserInfoInterceptor.java:51)

at com.jfinal.aop.Invocation.invoke(Invocation.java:69)

at com.majian.framework.common.interceptor.SiteInterceptor.intercept(SiteInterceptor.java:55)

at com.jfinal.aop.Invocation.invoke(Invocation.java:69)

at com.jfinal.ext.interceptor.SessionInViewInterceptor.intercept(SessionInViewInterceptor.java:44)

at com.jfinal.aop.Invocation.invoke(Invocation.java:69)

at com.jfinal.core.ActionHandler.handle(ActionHandler.java:81)

at com.jfinal.ext.handler.ContextPathHandler.handle(ContextPathHandler.java:48)

at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:86)

at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1634)

at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:533)

at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:146)

at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)

at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)

at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257)

at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595)

at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)

at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1340)

at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)

at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473)

at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564)

at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)

at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1242)

at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)

at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)

at org.eclipse.jetty.server.Server.handle(Server.java:503)

at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:364)

at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:260)

at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305)

at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)

at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118)

at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:765)

at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:683)

at java.lang.Thread.run(Thread.java:745)

Caused by: java.sql.SQLException: 调用中的无效参数

at oracle.jdbc.driver.AutoKeyInfo.getTableName(AutoKeyInfo.java:347)

at oracle.jdbc.driver.T4CConnection.doDescribeTable(T4CConnection.java:3823)

at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java:6677)

at com.alibaba.druid.filter.FilterChainImpl.connection_prepareStatement(FilterChainImpl.java:685)

at com.alibaba.druid.filter.FilterAdapter.connection_prepareStatement(FilterAdapter.java:962)

at com.alibaba.druid.filter.FilterEventAdapter.connection_prepareStatement(FilterEventAdapter.java:176)

at com.alibaba.druid.filter.FilterChainImpl.connection_prepareStatement(FilterChainImpl.java:681)

at com.alibaba.druid.wall.WallFilter.connection_prepareStatement(WallFilter.java:344)

at com.alibaba.druid.filter.FilterChainImpl.connection_prepareStatement(FilterChainImpl.java:681)

at com.alibaba.druid.filter.FilterAdapter.connection_prepareStatement(FilterAdapter.java:962)

at com.alibaba.druid.filter.FilterEventAdapter.connection_prepareStatement(FilterEventAdapter.java:176)

at com.alibaba.druid.filter.FilterChainImpl.connection_prepareStatement(FilterChainImpl.java:681)

at com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl.prepareStatement(ConnectionProxyImpl.java:366)

at com.alibaba.druid.pool.DruidPooledConnection.prepareStatement(DruidPooledConnection.java:485)

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 com.jfinal.plugin.activerecord.SqlReporter.invoke(SqlReporter.java:58)

at com.sun.proxy.$Proxy5.prepareStatement(Unknown Source)

at com.jfinal.plugin.activerecord.DbPro.save(DbPro.java:618)

at com.jfinal.plugin.activerecord.DbPro.save(DbPro.java:645)

... 47 more


评论区

马小酱

2018-11-07 12:59

我们的项目是不动产相关的,H表是国家规范表结构的命名,所以希望讨论能围绕问题本身原因和解决办法.

马小酱

2018-11-07 12:59

@jfinal 波总有什么看法?

JFinal

2018-11-07 13:15

自建一个类,继承一下 com.jfinal.plugin.activerecord.DbPro.java,覆盖其中的出问题的方法,改造正确

最后配置一下自己的实现:
arp.setDbProFactory(new MyDbProFactor());

注意,要先有一个:
public class MyDbPro extends DbPro {
...
}

再有一个 :
public class MyDbProFactory extends DbProFactory {
public DbPro getDbPro() {
return new MyDbPro();
}
}

然后才可以 arp.setDbProFactory(new MyDbProFactor());

热门分享

扫码入社