4

I've got some problems with a stored procedure on an Oracle database.

I just want to call a procedure (which has 50 IN parameters and 2 IN OUT parameters) and get these 2 OUT parameters.

I'm trying to execute() the associated CallableStatement but it returns me a NullPointerException

java.lang.NullPointerException
at oracle.jdbc.driver.T4C8Oall.getNumRows(T4C8Oall.java:977)
at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:1363)
...

Here is the code (I'm using Hibernate):

    Session session = (Session) HibernateUtil.currentSession();

    final Transaction transaction = session.beginTransaction();

    try {
        session.doWork(new Work() {

            public void execute(Connection connection) throws SQLException {
                try {
                    CallableStatement call = connection.prepareCall("{?,? = call geneva_admin.bksgnvcrmps.createorreturnproduct1nc(" +
                            "?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?," +
                            "?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?," +
                            "?,?,?,?,?,?,?,?,?,?,?,?)}");

                    int i = 1;

                    call.registerOutParameter(i++, Types.INTEGER);
                    call.registerOutParameter(i++, Types.VARCHAR);


                    call.setString(i++, typeofproduct);
                    call.setString(i++, shiptositenumber);
                    call.setString(i++, billtositenumber);
                    call.setString(i++, ordernumber);
                    call.setInt(i++, orderid);
                    ...
                    call.setInt(i++, errcode);
                    call.setString(i++, errmsg);

                    call.execute();

                    System.out.println("err_code: " + call.getString(1));
                    System.out.println("err_msg: " + call.getString(2));

                    call.close();
                    transaction.commit();
                } catch (SQLException e) {
                    throw new SQLException(e);
                }
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
        transaction.rollback();
        return false;
    }

If, before the execute(), I set

    call.setEscapeProcessing(false);

I've got a SQLSyntaxErrorException (ORA-00911: invalid character)

Could you help me ?

Fab


Here is the solution:

The 2 last parameters of the procedure are IN OUT. I thought that we had to manage them as OUT parameter :

CallableStatement call = connection.prepareCall("{?, ? = call bksgnvcrm.createorreturnproduct1nc(..., ?, ?)}");

But as they're IN OUT, these parameters have to be declared as IN :

CallableStatement call = connection.prepareCall("{call bksgnvcrm.createorreturnproduct1nc(..., ?, ?)}");

And finally register them as OUT like this :

call.registerOutParameter(i, Types.INTEGER);
call.setInt(i++, errcode);
call.registerOutParameter(i, Types.VARCHAR);
call.setString(i++, errmsg);

I hope this may help you :)

4

1 回答 1

5

我也有同样的问题。就我而言,我意识到在调用存储过程时我忘记了“调用”这个词。

"{ call myPackage.myProcedure(?,?,?,?) }"

这可能有一天会帮助其他人,谁知道...

于 2014-03-17T02:44:31.813 回答