mybatis+ojdbc6.jar的一个奇怪问题记录

简介:

使用以下代码、配置时,发生异常。

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public  interface  IRowPropSubInfoMapper {
     /**
      * 将数据写入行基础信息子表中
      *
      * @author 團長
      * @since 2013-12-19
      * @param row
      *            行基础信息。
      * @return 插入的行数
      * @throws SQLException
      *             数据库操作发生异常时将抛出此异常。
      * @deprecated 2013-12-19 改用批量操作
      */
     @Deprecated
     public  int  insertRowPropSubInfo(IRowPropSubInfoModel row)
             throws  SQLException;
}


mybatis的配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
< settings >
     <!-- 全局映射器启用缓存 -->
     < setting  name = "cacheEnabled"  value = "true"  />
     <!-- 查询时,关闭关联对象即时加载以提高性能 纳闷,加上这一行会报错。 <setting name="lazyLoadingEnabled"
         value="true" /> -->
     <!-- 设置关联对象加载的形态,此处为按需加载字段(加载字段由SQL指 定),不会加载关联表的所有字段,以提高性能 -->
     < setting  name = "aggressiveLazyLoading"  value = "true"  />
     <!-- 对于未知的SQL查询,允许返回不同的结果集以达到通用的效果 -->
     < setting  name = "multipleResultSetsEnabled"  value = "true"  />
     <!-- 允许使用列标签代替列名 -->
     < setting  name = "useColumnLabel"  value = "true"  />
     <!-- 允许使用自定义的主键值(比如由程序生成的UUID 32位编码作为键值),数据表的PK生成策略将被覆盖 -->
     < setting  name = "useGeneratedKeys"  value = "true"  />
     <!-- 给予被嵌套的resultMap以字段-属性的映射支持 -->
     < setting  name = "autoMappingBehavior"  value = "FULL"  />
     <!-- 对于批量更新操作缓存SQL以提高性能 -->
     < setting  name = "defaultExecutorType"  value = "REUSE"  />
     <!-- 数据库超过25000毫秒仍未响应则超时 -->
     < setting  name = "defaultStatementTimeout"  value = "25000"  />
</ settings >


sql语句配置(sql语句中配置的参数个数,即values中的参数个数,小于等于7个时则可以正常执行;大于7个时将抛出异常。异常信息见后续。)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
< insert  id = "insertRowPropSubInfo"
     parameterType = "com.sinosig.evaluation.fcff.model.dto.IRowPropSubInfoModel" >
     insert into
     t_eva_fcff_row_property values
     (#{fcffid,jdbcType=INTEGER},
     #{code,jdbcType=VARCHAR},
     #{name,jdbcType=VARCHAR},
     #{description,jdbcType=VARCHAR},
     #{isshow,jdbcType=VARCHAR},
     #{currentPremethodCode,    jdbcType=VARCHAR},
     #{currentPreValue, jdbcType=VARCHAR},
     #{currentScaleBase,    jdbcType=VARCHAR},
     #{warningDescription, jdbcType=VARCHAR})
</ insert >


spring类配置:

1
2
3
4
5
< bean  id = "RowPropSubInfoMapper"  class = "org.mybatis.spring.mapper.MapperFactoryBean"
     parent = "BaseMybatisDao" >
     < property  name = "mapperInterface"
         value = "com.sinosig.evaluation.fcff.dao.IRowPropSubInfoMapper"  />
</ bean >


数据源配置:

1
2
3
4
5
6
7
< bean  id = "dataSource"  class = "org.apache.commons.dbcp.BasicDataSource"
     destroy-method = "close" >
     < property  name = "driverClassName"  value = "oracle.jdbc.driver.OracleDriver"  />
     < property  name = "url"  value = "jdbc:oracle:thin:@10.10.164.115:1521:ceshidb"  />
     < property  name = "username"  value = "atip"  />
     < property  name = "password"  value = "atip"  />
</ bean >


测试代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
@Test
public  void  testInsert() {
     List<IRowPropSubInfoModel> rowList = initRowList();
     try  {
         int  count =  1 ;
         for  (IRowPropSubInfoModel iRowSubInfoModel : rowList) {
             System.out.println(count++);
             System.out.println( "fcffid = "  + iRowSubInfoModel.getFcffid());
             System.out.println( "code = "  + iRowSubInfoModel.getCode());
             System.out.println( "name = "  + iRowSubInfoModel.getName());
             System.out.println( "description = "
                     + iRowSubInfoModel.getDescription());
             System.out.println( "isshow = "  + iRowSubInfoModel.getIsshow());
             System.out.println( "currentPremethodCode = "
                     + iRowSubInfoModel.getCurrentPremethodCode());
             System.out.println( "currentPreValue = "
                     + iRowSubInfoModel.getCurrentPreValue());
             System.out.println( "currentScaleBase = "
                     + iRowSubInfoModel.getCurrentScaleBase());
             System.out.println( "warningDescription = "
                     + iRowSubInfoModel.getWarningDescription());
             mapper.insertRowPropSubInfo(iRowSubInfoModel);
         }
     catch  (SQLException e) {
         e.printStackTrace();
         fail();
     }
}


异常信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.ExecutorException: Error preparing statement.  Cause: java.lang.ArrayIndexOutOfBoundsException:  9
     at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java: 73 )
     at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java: 364 )
     at $Proxy5.insert(Unknown Source)
     at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java: 236 )
     at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java: 79 )
     at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java: 40 )
     at $Proxy31.insertRowPropSubInfo(Unknown Source)
     at test.com.sinosig.evaluation.fcff.dao.RowPropSubInfoMapperTest.testInsert(RowPropSubInfoMapperTest.java: 69 )
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java: 39 )
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java: 25 )
     at java.lang.reflect.Method.invoke(Method.java: 597 )
     at org.junit.runners.model.FrameworkMethod$ 1 .runReflectiveCall(FrameworkMethod.java: 44 )
     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java: 15 )
     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java: 41 )
     at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java: 20 )
     at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java: 79 )
     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java: 71 )
     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java: 49 )
     at org.junit.runners.ParentRunner$ 3 .run(ParentRunner.java: 193 )
     at org.junit.runners.ParentRunner$ 1 .schedule(ParentRunner.java: 52 )
     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java: 191 )
     at org.junit.runners.ParentRunner.access$ 000 (ParentRunner.java: 42 )
     at org.junit.runners.ParentRunner$ 2 .evaluate(ParentRunner.java: 184 )
     at org.junit.runners.ParentRunner.run(ParentRunner.java: 236 )
     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java: 50 )
     at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java: 38 )
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java: 467 )
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java: 683 )
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java: 390 )
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java: 197 )
Caused by: org.apache.ibatis.executor.ExecutorException: Error preparing statement.  Cause: java.lang.ArrayIndexOutOfBoundsException:  9
     at org.apache.ibatis.executor.statement.BaseStatementHandler.prepare(BaseStatementHandler.java: 91 )
     at org.apache.ibatis.executor.statement.RoutingStatementHandler.prepare(RoutingStatementHandler.java: 54 )
     at org.apache.ibatis.executor.ReuseExecutor.prepareStatement(ReuseExecutor.java: 73 )
     at org.apache.ibatis.executor.ReuseExecutor.doUpdate(ReuseExecutor.java: 46 )
     at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java: 108 )
     at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java: 75 )
     at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java: 145 )
     at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java: 134 )
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java: 39 )
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java: 25 )
     at java.lang.reflect.Method.invoke(Method.java: 597 )
     at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java: 354 )
     ...  29  more
Caused by: java.lang.ArrayIndexOutOfBoundsException:  9
     at oracle.jdbc.driver.OracleSql.computeBasicInfo(OracleSql.java: 950 )
     at oracle.jdbc.driver.OracleSql.getSqlKind(OracleSql.java: 623 )
     at oracle.jdbc.driver.OraclePreparedStatement.<init>(OraclePreparedStatement.java: 1212 )
     at oracle.jdbc.driver.T4CPreparedStatement.<init>(T4CPreparedStatement.java: 28 )
     at oracle.jdbc.driver.T4CDriverExtension.allocatePreparedStatement(T4CDriverExtension.java: 68 )
     at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java: 3140 )
     at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java: 3042 )
     at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java: 5890 )
     at org.apache.commons.dbcp.DelegatingConnection.prepareStatement(DelegatingConnection.java: 508 )
     at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareStatement(PoolingDataSource.java: 400 )
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java: 39 )
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java: 25 )
     at java.lang.reflect.Method.invoke(Method.java: 597 )
     at org.apache.ibatis.logging.jdbc.ConnectionLogger.invoke(ConnectionLogger.java: 53 )
     at $Proxy32.prepareStatement(Unknown Source)
     at org.apache.ibatis.executor.statement.PreparedStatementHandler.instantiateStatement(PreparedStatementHandler.java: 65 )
     at org.apache.ibatis.executor.statement.BaseStatementHandler.prepare(BaseStatementHandler.java: 82 )
     ...  41  more


改用ojdbc14-10.2.0.1.0.jar则不会出现上述问题。



本文转自 斯然在天边 51CTO博客,原文链接:http://blog.51cto.com/winters1224/1357930,如需转载请自行联系原作者

相关文章
|
6月前
|
SQL Java 数据库
【Mybatis-plus异常】mybatis-plus updateById方法更新不了空字符串和null的解决方法
【Mybatis-plus异常】mybatis-plus updateById方法更新不了空字符串和null的解决方法
136 0
|
10月前
|
Java 数据库连接 mybatis
面试官:讲一下Mybatis在SpringBoot中是如何被加载执行的?
本文主要讲述mybatis在springboot中是如何被加载执行的,由于涉及的内容会比较多,所以这次只会对调用关系及关键代码点进行讲解,为了避免文章太长,读起来昏昏欲睡,一些不影响整体流程的细节就不涉及了。
|
11月前
|
SQL Java 数据库连接
Mybatis 在SpringBoot中打印log日志
Mybatis 在SpringBoot中打印log日志
281 0
|
12月前
|
XML Java 关系型数据库
第一个Mybatis程序
第一个Mybatis程序
39 0
|
12月前
|
XML SQL Java
第一个MyBatis程序(上)
第一个MyBatis程序(上)
|
12月前
|
XML Java 测试技术
第一个MyBatis程序(下)
第一个MyBatis程序(下)
|
XML Oracle Java
mybatis 快速生成Java POJO文件及数据库Mapper文件【文末彩蛋】
mybatis 快速生成Java POJO文件及数据库Mapper文件【文末彩蛋】
169 0
mybatis 快速生成Java POJO文件及数据库Mapper文件【文末彩蛋】
|
SQL XML Java
第一个mybatis程序
第一个mybatis程序
260 0
|
SQL Java 数据库连接
mybatis plus注意的地方
1 可能你会觉得奇怪,明明我创建表的时候,设置id自增从1开始。自增主键,数据库设置了自增主键后,po类需要增加@TableId(type = IdType.AUTO),或者不要id字段才能生效。
113 0
mybatis plus注意的地方
|
XML Java 数据库连接
mybatis与spring整合步骤以及自己遇到的错误
mybatis与spring整合步骤以及自己遇到的错误
mybatis与spring整合步骤以及自己遇到的错误