`

Check the output parameters (register output parameters failed) IN Ibatis

阅读更多

使用IBatis 在调用Oracle 的存储过程 或者 函数时出现以下异常, 内容如下:

-----------------------------------------------------------------------------------------------

org.springframework.jdbc.UncategorizedSQLException: SqlMapClient operation; uncategorized SQLException for SQL []; SQL state [null]; error code [17004];  
--- The error occurred in ibatis-conf/MpsBillPayMainBean.xml. 
--- The error occurred while executing query procedure. 
--- Check the {?=call jtosa_fun_billpaymainlistcount(?,?,?)}. 
--- Check the output parameters (register output parameters failed). 
--- Cause: java.sql.SQLException: 无效的列类型; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:  
--- The error occurred in ibatis-conf/MpsBillPayMainBean.xml. 
--- The error occurred while executing query procedure. 
--- Check the {?=call jtosa_fun_billpaymainlistcount(?,?,?)}. 
--- Check the output parameters (register output parameters failed). 
--- Cause: java.sql.SQLException: 无效的列类型
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
    at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:212)
    at org.springframework.orm.ibatis.SqlMapClientTemplate.executeWithMapResult(SqlMapClientTemplate.java:260)
    at org.springframework.orm.ibatis.SqlMapClientTemplate.queryForMap(SqlMapClientTemplate.java:372)
    at com.jtosa.dao.impl.BillPayMainDaoImpl.findBillPayMainListCount(BillPayMainDaoImpl.java:31)
    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.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    at $Proxy11.findBillPayMainListCount(Unknown Source)
    at com.jtosa.service.impl.BillPayMainServiceImpl.searchBillPayMainListCount(BillPayMainServiceImpl.java:20)
    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.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    at $Proxy30.searchBillPayMainListCount(Unknown Source)
    at com.jtosa.service.impl.test.BillPayMainServiceImplTest.testSearchBillPayMainListCount(BillPayMainServiceImplTest.java:30)
    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.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
    at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
    at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
    at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
    at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
    at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
    at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
    at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
    at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
    at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:  
--- The error occurred in ibatis-conf/MpsBillPayMainBean.xml. 
--- The error occurred while executing query procedure. 
--- Check the {?=call jtosa_fun_billpaymainlistcount(?,?,?)}. 
--- Check the output parameters (register output parameters failed). 
--- Cause: java.sql.SQLException: 无效的列类型
    at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:201)
    at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryForList(MappedStatement.java:139)
    at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:567)
    at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:541)
    at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForMap(SqlMapExecutorDelegate.java:658)
    at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForMap(SqlMapExecutorDelegate.java:640)
    at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForMap(SqlMapSessionImpl.java:148)
    at org.springframework.orm.ibatis.SqlMapClientTemplate$7.doInSqlMapClient(SqlMapClientTemplate.java:374)
    at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:209)
    ... 47 more
Caused by: java.sql.SQLException: 无效的列类型
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
    at oracle.jdbc.driver.OracleStatement.getInternalType(OracleStatement.java:3424)
    at oracle.jdbc.driver.OracleCallableStatement.registerOutParameterInternal(OracleCallableStatement.java:125)
    at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:268)
    at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:348)
    at com.mchange.v2.c3p0.impl.NewProxyCallableStatement.registerOutParameter(NewProxyCallableStatement.java:311)
    at com.ibatis.sqlmap.engine.execution.SqlExecutor.registerOutputParameters(SqlExecutor.java:431)
    at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQueryProcedure(SqlExecutor.java:274)
    at com.ibatis.sqlmap.engine.mapping.statement.ProcedureStatement.sqlExecuteQuery(ProcedureStatement.java:39)
    at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:189)
    ... 55 more

----------------------------------------------------------------------------------------------------

 

 

错误原因是:数据类型不正确.   

 

<parameterMap class="java.util.HashMap" id="listparamMap">
        <parameter property="skipSize" javaType="java.lang.Integer" jdbcType="NUMBER" mode="IN"/>
        <parameter property="pageSize" javaType="java.lang.Integer" jdbcType="NUMBER" mode="IN"/>
        <parameter property="payTime" javaType="java.lang.String" jdbcType="VARCHAR2" mode="IN"/>
        <parameter property="payEndTime" javaType="java.lang.String" jdbcType="VARCHAR2" mode="IN"/>
        <parameter property="cityCode" javaType="java.lang.String" jdbcType="VARCHAR2" mode="IN"/>
        <parameter property="u_cursor" javaType="java.sql.ResultSet" jdbcType="ORACLECURSOR " mode="OUT"/>
    </parameterMap>

 

    <parameterMap class="java.util.HashMap" id="paramMap">
        <parameter property="total" jdbcType="NUMBER " javaType="java.lang.Long" mode="OUT"/>
        <parameter property="payTime" jdbcType="VARCHAR" javaType="java.lang.String" mode="IN"/>
        <parameter property="payEndTime" jdbcType="VARCHAR" javaType="java.lang.String" mode="IN"/>
        <parameter property="cityCode"  jdbcType="VARCHAR" javaType="java.lang.String" mode="IN"/>
    </parameterMap>
   
    <procedure id="findBillPayMainListCount" parameterMap="paramMap" resultClass="java.lang.Long">
        {?=call jtosa_fun_billpaymainlistcount(?,?,?)}
    </procedure>

    <procedure id="findBillPayMainList" parameterMap="listparamMap" resultMap="BillPayMainBean">
        {call jtosa_porc_billPayMainList(?,?,?,?,?,?)}
    </procedure>

----------------------------------------------------------------------------------

 

NUMBER 是oracle 数据库中的数据类型,但是在java.sql.Types 中并没有些常量.

 

只要将NUMBER 替换成java.sql.Types 中存在即可.

 

    setType("ARRAY", Types.ARRAY);
    setType("BIGINT", Types.BIGINT);
    setType("BINARY", Types.BINARY);
    setType("BIT", Types.BIT);
    setType("BLOB", Types.BLOB);
    setType("BOOLEAN", JDBC_30_BOOLEAN);
    setType("CHAR", Types.CHAR);
    setType("CLOB", Types.CLOB);
    setType("DATALINK", JDBC_30_DATALINK);
    setType("DATE", Types.DATE);
    setType("DECIMAL", Types.DECIMAL);
    setType("DISTINCT", Types.DISTINCT);
    setType("DOUBLE", Types.DOUBLE);
    setType("FLOAT", Types.FLOAT);
    setType("INTEGER", Types.INTEGER);
    setType("JAVA_OBJECT", Types.JAVA_OBJECT);
    setType("LONGVARBINARY", Types.LONGVARBINARY);
    setType("LONGVARCHAR", Types.LONGVARCHAR);
    setType("NULL", Types.NULL);
    setType("NUMERIC", Types.NUMERIC);
    setType("OTHER", Types.OTHER);
    setType("REAL", Types.REAL);
    setType("REF", Types.REF);
    setType("SMALLINT", Types.SMALLINT);
    setType("STRUCT", Types.STRUCT);
    setType("TIME", Types.TIME);
    setType("TIMESTAMP", Types.TIMESTAMP);
    setType("TINYINT", Types.TINYINT);
    setType("VARBINARY", Types.VARBINARY);
    setType("VARCHAR", Types.VARCHAR);

    setType("CH", Types.CHAR);
    setType("VC", Types.VARCHAR);

    setType("DT", Types.DATE);
    setType("TM", Types.TIME);
    setType("TS", Types.TIMESTAMP);

    setType("NM", Types.NUMERIC);
    setType("II", Types.INTEGER);
    setType("BI", Types.BIGINT);
    setType("SI", Types.SMALLINT);
    setType("TI", Types.TINYINT);

    setType("DC", Types.DECIMAL);
    setType("DB", Types.DOUBLE);
    setType("FL", Types.FLOAT);

    setType("ORACLECURSOR", -10);

-----------------------------------------------------------------------------

 

看到ORACLECURSOR 你也许会得到什么启示.......... (看下IBatis Bean 的 映射文件)

 

 

正确的映射:

 

    <parameterMap class="java.util.HashMap" id="listparamMap">
        <parameter property="skipSize" javaType="java.lang.Integer" jdbcType="NUMBER" mode="IN"/>
        <parameter property="pageSize" javaType="java.lang.Integer" jdbcType="NUMBER" mode="IN"/>
        <parameter property="payTime" javaType="java.lang.String" jdbcType="VARCHAR2" mode="IN"/>
        <parameter property="payEndTime" javaType="java.lang.String" jdbcType="VARCHAR2" mode="IN"/>
        <parameter property="cityCode" javaType="java.lang.String" jdbcType="VARCHAR2" mode="IN"/>
        <parameter property="u_cursor" javaType="java.sql.ResultSet" jdbcType="ORACLECURSOR" mode="OUT"/>
    </parameterMap>
   
    <parameterMap class="java.util.HashMap" id="paramMap">
        <parameter property="total" javaType="java.lang.Long" jdbcType="DOUBLE" mode="OUT"/>
        <parameter property="payTime" javaType="java.lang.String" jdbcType="VARCHAR2" mode="IN"/>
        <parameter property="payEndTime" javaType="java.lang.String" jdbcType="VARCHAR2" mode="IN"/>
        <parameter property="cityCode" javaType="java.lang.String" jdbcType="VARCHAR2" mode="IN"/>
    </parameterMap>
   
    <procedure id="findBillPayMainListCount" parameterMap="paramMap" resultClass="java.lang.Long">
        {?=call jtosa_fun_billpaymainlistcount(?,?,?)}
    </procedure>
   
    <procedure id="findBillPayMainList" parameterMap="listparamMap" resultMap="BillPayMainBean">
        {call jtosa_porc_billPayMainList(?,?,?,?,?,?)}
    </procedure>

 

 

 

 

 

 

分享到:
评论
3 楼 mikey_5 2013-09-02  
非常感谢楼主的分享,<parameter property="returnId" javaType="java.lang.Integer"
jdbcType="DOUBLE" mode="OUT" /> 原来要使用Double,谢谢
2 楼 影子_890314 2012-11-06  
我现在也有这个错误,求解!
1 楼 wjpiao 2011-11-28  
你下面的“正确的映射”里面不是还是有number类型吗?

相关推荐

    ibatis in action 中文版3ibatis in action 中文版3

    ibatis in action 中文版3ibatis in action 中文版3ibatis in action 中文版3ibatis in action 中文版3

    ibatis in action 中文版7ibatis in action 中文版7

    根据提供的信息来看,这里主要涉及的是《ibatis in action》这本书的相关内容分享。不过由于描述与部分内容中的信息并不完整,且存在乱码情况,我们难以直接从中提取具体的知识点。因此,下面将围绕《ibatis in ...

    IBATIS_IN_ACTION

    《IBATIS_IN_ACTION》是一本深度探讨iBATIS框架应用与实践的专业书籍,由Clinton Begin、Brandon Goodin和Larry Meadors共同编写。本书详细介绍了iBATIS这一流行开源框架的核心概念、工作原理以及在实际项目中的应用...

    ibatis in action 电子书(pdf)

    《iBATIS in Action》是一本专注于讲解iBATIS框架使用的专业书籍,它为开发者提供了深入浅出的指导,帮助他们有效地在项目中应用这一强大的持久层解决方案。iBATIS,一个由Apache软件基金会维护的开源项目,是Java...

    《ibatis in action 》电子书及配书代码

    《iBatis in Action》是一本专为Java开发者编写的权威指南,深入讲解了iBatis和MyBatis这两个流行的持久层框架。这本书通过实践案例,详细阐述了如何有效地使用iBatis进行数据库操作,以及如何平滑过渡到MyBatis,...

    iBatis iBatis in Action iBatis实战

    那么iBatis作者编著的这本《iBatis in Action》是最好的选择了!至于下载资源则是原著引进中国之后出版的官方中文版,大大的方便大家阅读,学习!完整的资源是91.6M,格式为pdf。值得下载! 因为较大所以分成了两个...

    iBATIS in Action中文版(iBATIS实战 有水印) 第三部分

    iBATIS in Action中文版(iBATIS实战 有水印) 第三部分

    ibatis in action 中文详解

    在网上一个牛人翻译的ibatis in action,他分成了几个内容来翻译,我感觉不错,就把各部分分开弄成了word格式,还没翻译完,但是现有的翻译的部分就值得我们研究了。很适用的东西,还附带有代码。大家看看

    ibatis、mybatis官方教程文档集合(含Manning.iBATIS.in.Action)

    Manning.iBATIS.in.Action.Jan.2007.eBook-BBL.pdf MyBatis 3 User Guide Simplified Chinese.pdf MyBatis-3.0.3-Migrations.pdf MyBatis-3.0.3-User-Guide.pdf MyBatis-3-Migrations.doc MyBatis-3-Migrations.pdf ...

    iBATIS in Action中文版(iBATIS实战 有水印) 第一部分

    一共七个分卷 iBATIS in Action中文版(iBATIS实战 有水印) 第一部分

    ibatis in action 中文版4ibatis in action 中文版4

    ibatis in action 中文版4ibatis in action 中文版4ibatis in action 中文版4ibatis in action 中文版4

    ibatis in action 中文版1

    ibatis in action 中文版1ibatis in action 中文版1ibatis in action 中文版1

    ibatis3.0中in的用法

    ### ibatis3.0中`in`的用法详解 #### 一、引言 在进行数据库查询时,经常会遇到需要根据多个值进行查询的情况,这时`IN`语句就显得尤为重要。`IN`语句可以用于判断某个字段的值是否在一个指定的列表之中,非常适用...

    ibatis总结 ibatis ibatis ibatis ibatis

    Ibatis 是一款轻量级的Java持久层框架,它允许开发者将SQL语句与Java代码分离,从而使得数据库访问更加灵活、易于维护。本篇文章将深入探讨Ibatis的核心概念、最佳实践以及与其他框架如Struts和Spring的整合。 1. ...

    ibatis in action ibatis实战 - 2

    ibatis实战中文版 一共2个文件 ibatis in action

    ibatis in action 中文

    《iBatis in Action》是一本专注于iBatis框架的权威指南,中文版虽然未完成,但已经提供了宝贵的中文学习资料。iBatis是Java世界里一个流行的数据访问层(Data Access Layer)框架,它旨在简化数据库操作,将SQL与...

    ibatis in action 中文版2ibatis in action 中文版2

    ibatis in action 中文版2ibatis in action 中文版2

    Manning iBATIS in Action

    《Manning iBATIS in Action》是一本专为Java开发者设计的权威指南,全面深入地介绍了iBATIS这一持久层框架。iBATIS是Java世界中一个流行的数据访问框架,它将SQL映射与对象模型相结合,简化了数据库操作,提高了...

    ibatis in action ibatis实战 中文版 - 1

    ibatis实战中文版 一共2个文件 ibatis in action

    Manning Ibatis In Action Jan 2007 Ebook-Bbl.pdf

    根据提供的文件信息,我们可以从《ibatis in action》这本电子书中提炼出多个与iBATIS框架相关的知识点。以下是对这些知识点的详细说明: ### 一、iBATIS概述 **标题**: "Manning Ibatis In Action Jan 2007 Ebook...

Global site tag (gtag.js) - Google Analytics