plsql中out参数为cursor时报错
Caused by: java.sql.SQLException: 不明确的 java.sql.Type,请使用 IfxRegisterOutParameter()。
at com.gbasedbt.util.IfxErrMsg.getSQLException(IfxErrMsg.java:409)
at com.gbasedbt.jdbc.IfxCallableStatement.b(IfxCallableStatement.java:688)
at com.gbasedbt.jdbc.IfxCallableStatement.registerOutParameter(IfxCallableStatement.java:623)
at org.apache.ibatis.executor.statement.CallableStatementHandler.registerOutputParameters(CallableStatementHandler.java:113)
at org.apache.ibatis.executor.statement.CallableStatementHandler.parameterize(CallableStatementHandler.java:97)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize(RoutingStatementHandler.java:64)
at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:88)
at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62)
create or replace procedure p2(m int,n out sys_refcursor) is
begin
OPEN n FOR select tabname from systables where tabid < 10;
end;
/
<select id="getProc1" statementType="CALLABLE" resultType="com.wang.entity.OcursorRet">
call p2(
#{mm,mode=IN,jdbcType=INTEGER},
#{ret,mode=OUT,jdbcType=CURSOR,javaType=java.sql.ResultSet,resultMap=myout}
)
</select>
原因为 oracle 中的游标类型为 cursor(-10) gbase8s 中游标类型为IFX_TYPE_CURSOR(2100)
解决方案,在类型为cursor 单独处理
在CallableStatementHandler.registerOutputParameters
private void registerOutputParameters(CallableStatement cs) throws SQLException {
List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
for (int i = 0, n = parameterMappings.size(); i < n; i++) {
ParameterMapping parameterMapping = parameterMappings.get(i);
if (parameterMapping.getMode() == ParameterMode.OUT || parameterMapping.getMode() == ParameterMode.INOUT) {
if (null == parameterMapping.getJdbcType()) {
throw new ExecutorException("The JDBC Type must be specified for output parameter. Parameter: " + parameterMapping.getProperty());
} else {
if (parameterMapping.getNumericScale() != null && (parameterMapping.getJdbcType() == JdbcType.NUMERIC || parameterMapping.getJdbcType() == JdbcType.DECIMAL)) {
cs.registerOutParameter(i + 1, parameterMapping.getJdbcType().TYPE_CODE, parameterMapping.getNumericScale());
} else {
if (parameterMapping.getJdbcTypeName() == null || parameterMapping.getJdbcTypeName().equals("CURSOR")) {
//cs.registerOutParameter(i + 1, parameterMapping.getJdbcType().TYPE_CODE);
//gbase8s cursor
cs.registerOutParameter(i+1, IfxTypes.IFX_TYPE_CURSOR);
} else {
cs.registerOutParameter(i + 1, parameterMapping.getJdbcType().TYPE_CODE, parameterMapping.getJdbcTypeName());
}
}
}
}
}
}