开发者

How to propagate a value back to the enclosing class in Java?

I was looking at this example Oracle function from Hibernate. It tells in the solution开发者_C百科 that:

int result = call.getInt(1); // propagate this back to enclosing class

Can anyone point me to how this can be done?


Here's an example of returning a String instead of an int and propagate this back to enclosing class

String results = sessionFactory.getCurrentSession().doReturningWork(
    new ReturningWork<String>() {
        public String execute(Connection connection) throws SQLException {
            CallableStatement call = connection.prepareCall("{ ? = call emb_copy_tool_fc(?,?,?) }");
            call.registerOutParameter( 1, Types.VARCHAR ); // or whatever it is
            call.setString(2, t_order_headers_id);
            call.setString(3, t_new_order_headers_id);
            call.setString(4, p_by);
            call.execute();
            String result = call.getString(1); // propagate this back to enclosing class
            return result;
        }
    });


This is talking about output parameters of Stored procedure. The link you shown, is actually calling a Stored procedure and getting the output parameter from the PrepareCall, after its been executed successfully.

For this, you need to understand how Output parameters work in SPs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜