mybatis与gbase8s plsql适配问题一

在使用 mybatis 调用 gbase8s oracle模式下创建的plsql时 ,出现空指针的报错

Caused by: java.lang.NullPointerException
    at com.gbasedbt.jdbc.IfxCallableStatement.getResultSet(IfxCallableStatement.java:267)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getFirstResultSet(DefaultResultSetHandler.java:240)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:188)
    at org.apache.ibatis.executor.statement.CallableStatementHandler.query(CallableStatementHandler.java:69)
    at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79)
    at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:63)
    at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:328)
    at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:157)
    at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
    at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:89)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:151)

create or replace procedure p1(m int, n out int) is
a int;
begin
select 1 into a from dual;
n:=a;
end;
/
        HashMap hashMap = new HashMap();
        hashMap.put("mm",23);
        tableOneMapper.getProc(hashMap);
        System.out.println(hashMap.get("ret"));

整体调用逻辑如下

execute(SqlSession sqlSession, Object[] args)  -->
sqlSession.selectOne(command.getName(), param);  -->
this.selectList(statement, parameter);  -->
this.selectList(statement, parameter, RowBounds.DEFAULT);  -->
selectList(statement, parameter, rowBounds, Executor.NO_RESULT_HANDLER);  -->
executor.query(ms, wrapCollection(parameter), rowBounds, handler);  -->
query(ms, parameterObject, rowBounds, resultHandler, key, boundSql);  -->
delegate.query(ms, parameterObject, rowBounds, resultHandler, key, boundSql);  -->
queryFromDatabase(ms, parameter, rowBounds, resultHandler, key, boundSql);  -->
doQuery(ms, parameter, rowBounds, resultHandler, boundSql);  -->
handler.query(stmt, resultHandler);  -->
delegate.query(statement, resultHandler);  -->
resultSetHandler.handleResultSets(cs);  -->
getFirstResultSet(stmt);  -->
gbasedbt.jdbc getResultSet();

其中在最终调用到gbasedbt.jdbc 下的 getResultSet 方法时,当resultset为空时 会直接throw Exception ,将异常传递给上层,导致最终空指针错误

解决方案

1  使用 标签去调用plsql

2 在getResultSet 的上一层 主动 try catch 异常

    private ResultSetWrapper getFirstResultSet(Statement stmt) throws SQLException {
        ResultSet rs;
        try {
            rs = stmt.getResultSet();
        }catch (Exception e){
            rs=null;
        }
        while (rs == null) {
            // move forward to get the first resultset in case the driver
            // doesn't return the resultset as the first result (HSQLDB 2.1)
            if (stmt.getMoreResults()) {
                rs = stmt.getResultSet();
            } else {
                if (stmt.getUpdateCount() == -1) {
                    // no more results. Must be no resultset
                    break;
                }
            }
        }
        return rs != null ? new ResultSetWrapper(rs, configuration) : null;
    }

你可能感兴趣的:(gbase8s,数据库)