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

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

代码:

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的配置:

<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个时将抛出异常。异常信息见后续。)

<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类配置:

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


数据源配置:

<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>


测试代码:

@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();
    }
}


异常信息:

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则不会出现上述问题。

本文出自 “编程的摩羯男” 博客,请务必保留此出处http://winters1224.blog.51cto.com/3021203/1357930

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。