2

对于单一输出类型,我的代码工作正常,但我不知道如何执行具有多个输出参数的 Oracle 过程以及输出是什么,即 ResultSet、Number 等。

 abcProcedure(param1 OUT NUMBER,param2 OUT NUMBER,param3 OUT NUMBER,param4 OUT NUMBER,param5 IN OUT NUMBER, param6 IN NUMBER,param7 IN NUMBER)

休眠代码:

 session.doWork(new Work(){

public void execute(Connection connection) throws SQLException {

CallableStatement callableStatement=connection.prepareCall("{call abcProcedure(?,?,?,?,?,?,?)}");


callableStatement.registerOutParameter(registerOutParameter,types.Numeric);

.......
callableStatement.execute();



}
}

有谁知道这是怎么做到的吗?

4

2 回答 2

2

最后我自己解决了。这是解决方案

callableStatement.registerOutParameter(1,types.Numeric); //1   index of Out parameter
callableStatement.registerOutParameter(2,types.Numeric); //2   index of Out parameter
callableStatement.registerOutParameter(3,types.Numeric); //3   index of Out parameter
callableStatement.registerOutParameter(2,types.Numeric); //4   index of Out parameter
callableStatement.registerOutParameter(5,types.Numeric); //5   index of Out parameter
callableStatement.setLong(5, (Long)value); // 5 is also  input parameter
callableStatement.setLong(6, (Long)value); // 6    input parameter
callableStatement.setLong(7, (Long)value); // 7    input parameter
callableStatement.execute();
callableStatement.getLong(1);// out put for param1 
callableStatement.getLong(2);// out put for param2
callableStatement.getLong(3);// out put for param3
callableStatement.getLong(4);// out put for param4
callableStatement.getLong(5);// out put for param5

如果有多个结果集

callableStatement.getResultSet(); // will get the first ResultSet
callableStatement.getMoreResults();// will point to the next ResultSet
callableStatement.getResultSet();// will get the second ResultSet
..... So on

而已。:-)

于 2012-03-23T08:05:52.327 回答
0

使用上述评论,我能够解决与我的项目相关的问题。我能够使用会话工厂调用存储过程。代码如下。

    public double getQuant(String Cd, String Num) {
          double vTotRet = 0;
          double vTotCst = 0;
          double onOrdQty = 0;
                 Session sess = sessionFactory.openSession();
                 Connection conn = sess.connection();
                 CallableStatement callableStatement = conn.prepareCall("{call MyProcedure(?,?,?,?,?)}");
                 //Setting the first two parameters
                 callableStatement.setString(1,Num);
                 callableStatement.setString(2,Cd);
                 //Initializing the out parameters
                 callableStatement.registerOutParameter(3, Types.DOUBLE);                   
                 callableStatement.registerOutParameter(4, Types.DOUBLE);
                 callableStatement.registerOutParameter(5, Types.DOUBLE);
                 //Execute the stored procedure
                 callableStatement.execute();
                 vTotRet = callableStatement.getDouble(3);
                 vTotCst = callableStatement.getDouble(4);
                 onOrdQty = callableStatement.getDouble(5);
                 logger.info(onOrdQty);
                 return onOrdQty;
          }
于 2012-12-07T05:31:51.880 回答