java.sql.SQLException: ORA-01008: 并非所有变量都使用 Mybatis 3 绑定

Posted

技术标签:

【中文标题】java.sql.SQLException: ORA-01008: 并非所有变量都使用 Mybatis 3 绑定【英文标题】:java.sql.SQLException: ORA-01008: not all variables bound using Mybatis 3 【发布时间】:2014-04-17 14:27:05 【问题描述】:

所以我使用 Mybatis 3 来进行过程调用。这是我第一次使用这种方法调用 oracle 数据库(其他时候是 mysql 数据库),我得到了上面提到的错误。我从来没有遇到过以相同方式调用 mysql 数据库的问题,我需要对 oracle 做些什么特别的事情吗?看来这个错误信息一般表示参数的个数还是'?与设置的内容不匹配,但从我的 xml 文件中可以看出,我正在设置所有参数。

10:07:22,079 [DEBUG] call.authenticateCmplnr - ooo Using Connection [oracle.jdbc.driver.OracleConnection@543d1aa8]
10:07:22,083 [DEBUG] call.authenticateCmplnr - ==>  Preparing: CALL TDU_LOGIN_USER_CHECK( ?, ?, ?, ?, ? ) 
10:07:22,129 [DEBUG] call.authenticateCmplnr - ==> Parameters: m440109(String), TDU(String)
org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.sql.SQLException: ORA-01008: not all variables bound

### The error may exist in com/cmplnr/datasource/dataservice.xml
### The error may involve call.authenticateCmplnr-Inline
### The error occurred while setting parameters
### SQL: CALL TDU_LOGIN_USER_CHECK(    ?,    ?,    ?,    ?,    ?   )
### Cause: java.sql.SQLException: ORA-01008: not all variables bound

    at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:107)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:98)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:62)
    at com.cmplnr.integration.AuthenticationServiceImpl.authorizeAccess(AuthenticationServiceImpl.java:80)
    at com.cmplnr.integration.AuthenticationServiceImpl.authenticateCmplnr(AuthenticationServiceImpl.java:53)
    at com.cmplnr.control.TDU_Control.test(TDU_Control.java:24)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:174)
    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:421)
    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:409)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1813)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.sql.SQLException: ORA-01008: not all variables bound

    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
    at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
    at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:590)
    at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1973)
    at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1119)
    at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2191)
    at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:2064)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2989)
    at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:658)
    at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:736)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:55)
    at $Proxy14.execute(Unknown Source)
    at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:56)
    at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:70)
    at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:57)
    at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:259)
    at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:132)
    at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:105)
    at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:81)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:104)
    ... 34 more

我的实现

private User authorizeAccess(String id)
        SqlSession session = sqlSessionFactory.openSession();

        Map<String,Object>params = new HashMap<String,Object>();
        params.put("id", id);
        params.put("cycleType", "TDU");

        User user = null;

        try
            user = session.selectOne("call.authenticateCmplnr", params);
        catch(Exception e)
            e.printStackTrace();
            return null;
        finally
            session.close();
        

        return user;

    

xml 文件

<mapper namespace="call">

    <resultMap id = "userMap" type="com.cmplnr.core.User">
        <result property="id" column="ATTRIBUTE1"/>
        <result property="fullName" column="USER_NAME"/>
    </resultMap>

    <select id = "authenticateCmplnr" parameterType="java.util.Map">
        CALL TDU_LOGIN_USER_CHECK(
            #id, mode=IN, jdbcType=VARCHAR,
            #cycleType, mode=IN, jdbcType=VARCHAR,
            #cursor, mode=OUT, jdbcType=CURSOR, resultMap=userMap,
            #errcode, mode=OUT, jdbcType=INTEGER,
            #errmsg, mode=OUT, jdbcType=VARCHAR
        )
    </select>

</mapper>

【问题讨论】:

这是我第一次听说mybatis,因此仅作为建议。该错误基本上是说您没有提供进行 JDBC 调用所需的所有变量。我猜你只提供了 2 个 mode=IN 类型的变量,它希望提供所有 5 个(包括 3 个 mode=OUT 类型)。 【参考方案1】:

您可以尝试将您的 OUT 参数与空值一起放入 Map 吗? 你可以看到这可能是欺骗answer。

private User authorizeAccess(String id)
    SqlSession session = sqlSessionFactory.openSession();

    Map<String,Object>params = new HashMap<String,Object>();
    params.put("id", id);
    params.put("cycleType", "TDU");
    params.put("cursor", null);
    params.put("errcode", null);
    params.put("errmsg", null);

    User user = null;

    try
        user = session.selectOne("call.authenticateCmplnr", params);
    catch(Exception e)
        e.printStackTrace();
        return null;
    finally
        session.close();
    

    return user;


【讨论】:

以上是关于java.sql.SQLException: ORA-01008: 并非所有变量都使用 Mybatis 3 绑定的主要内容,如果未能解决你的问题,请参考以下文章

Python 操作Redis

python爬虫入门----- 阿里巴巴供应商爬虫

Python词典设置默认值小技巧

《python学习手册(第4版)》pdf

Django settings.py 的media路径设置

Python中的赋值,浅拷贝和深拷贝的区别