1

I am trying to call a stored procedure from Java using JDBC4PreparedStatement. The stored procedure takes in two input parameters and one output. I set the two input parameters by calling preparedStatement.setString(index, param)

but I tried the same for the output and get this error: OUT or INOUT argument 3 for routine db.deleteItem is not a variable or NEW pseudo-variable in BEFORE trigger

Is there a specific type I need to use? If so, how do I set it? I couldn't find any good examples.

Thanks

Seephor
  • 1,692
  • 3
  • 28
  • 50

2 Answers2

1

You should not use a prepared statement for that, but a callable statement instead. You can consider a callable statement a prepared statement with extra features to support stored procedures (including things like OUT parameters).

To register out parameters, you can use CallableStatement.registerOutParameter.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
0

When we mark parameters as OUT or INOUT, the expectation is that the SP should be able to work with these parameters and at the same time it should be a Variable instead of a value. This variable then can be used at a later point in time.

A value for an OUT / INOUT parameter to the SP doesn't make much sense as the SP can't manipulate the value and hence the error. We just can pass values for IN parameters alone.

You can refer to this documentation here which states:

To get back a value from a procedure using an OUT or INOUT parameter, pass the parameter by means of a user variable, and then check the value of the variable after the procedure returns. (If you are calling the procedure from within another stored procedure or function, you can also pass a routine parameter or local routine variable as an IN or INOUT parameter.)

So, what you can do is something similar to the accepted answer here!

CALL alextest10 ('p99', 'Madeuppy', '999', 'w9', @a_message);
SELECT @a_message;

Hope this helps!

Community
  • 1
  • 1
N00b Pr0grammer
  • 4,503
  • 5
  • 32
  • 46
  • helpful, and I am able to do this in SQL. I am trying to see how I can assign an INOUT parameter from PreparedStatement, but it looks like it does not support it and CallableStatement does. – Seephor Jan 31 '17 at 05:59