我有这个PLSQL程序:
procedure GetContractInfo(RequestID number, ParamNames out TVarcharArray, ParamValues out TVarcharArray,
SessionID in IRBiS_Const.TSessionID default null);
TVarcharArray
是:
type TVarcharArray is table of varchar2(255) index by binary_integer;
我想用Java调用它。这就是我的方式:
sessionFactory.getCurrentSession().doWork(new Work() {
public void execute(Connection con) throws SQLException {
OracleCallableStatement callableStatement = null;
try {
callableStatement = (OracleCallableStatement) con
.prepareCall("begin PREQUEST.GetContractInfo(?,?,?,?); end;");
callableStatement.setInt(1, request_id);
callableStatement.setString(4, sessionId);
//callableStatement.registerOutParameter(2, Types.ARRAY, "PREQUEST.TVarcharArray");
//callableStatement.registerOutParameter(3, Types.ARRAY, "PREQUEST.TVarcharArray");
callableStatement.registerIndexTableOutParameter(2, 16,
OracleTypes.VARCHAR, 0);
callableStatement.registerIndexTableOutParameter(3, 16,
OracleTypes.VARCHAR, 0);
callableStatement.execute();
System.out.println(callableStatement.getARRAY(2)
.getArray() == null); // NullPointer
} finally {
if (callableStatement != null) {
callableStatement.close();
}
}
}
});
但NullPointerException
就是我所拥有的一切。可能有什么不对?
答案 0 :(得分:2)
将第2和第3个参数设置为OracleTypes.ARRAY
,如下所示。对于自定义类型
callableStatement.registerOutParameter(2,
OracleTypes.ARRAY, "PREQUEST.TVARCHARARRAY");
callableStatement.registerOutParameter(3,
OracleTypes.ARRAY, "PREQUEST.TVARCHARARRAY");