I need to call an AS400 stored proc via SQL using a JTOPEN (JDBC) connection which accepts 1 INOUT and 4 IN params. I am doing this with the following SQL
CALL MYLIB.MYSP( ? ,'AJAJA1', '11111111', 'ą, ę, ć, ł, ń, ś, ż, ź', '0')
but it throws an error
[SQL0313] Number of host variables not valid.
If I use '' instead of a question mark then I get
[SQL0469] IN, OUT, or INOUT not valid for parameter 1 in procedure MYSP in MYLIB.
Is this possible?
Since first parameter of the stored procedure is an INOUT parameter, you need to use a CallableStatement object, register the first parameter as an output parameter, and set value of the first parameter.
JTOpen has a JDBC client that uses reflection to call Java methods. Here is an example of calling a stored procedure where the first parameter is an inout parameter. (Note: The program generates a lot of noise because it tries to guess which method to call. If one method fails, it tries another. Also, the 12 in the registerOutParameter call is really java.sql.Type.VARCHAR)