0
所以我使用Mybatis 3來進行過程調用。這是我第一次使用這種方法來調用一個oracle數據庫(其他時間它是一個MySQL數據庫),我得到了上述錯誤。我從來沒有遇到過以同樣的方式創建mysql數據庫調用的問題,有沒有什麼特別的我需要用oracle做些什麼?看來這個錯誤信息通常意味着參數的數量或'?'不匹配正在設置的內容,但從我的xml文件中可以看出,我正在設置所有參數。java.sql.SQLException:ORA-01008:並非所有變量都使用Mybatis 3綁定3
10:07:22,079 [DEBUG] {call.authenticateCmplnr} - ooo Using Connection [[email protected]]
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'類型)。 – anonymous