We have a stored procedure in a PostgreSQL DB that takes multiple input and multiple out parameters. The procedure call from the PG Admin client works fine when we do the following,
call proc1(input1, input2, output1, output2)
However, if we try to make this call through a JDBC CallableStatement, we get the below error,
org.postgresql.util.PSQLException: This statement does not declare an OUT parameter. Use { ?= call ... } to declare one.
at org.postgresql.jdbc.PgCallableStatement.registerOutParameter(PgCallableStatement.java:205)
The PostgreSQL driver is "org.postgresql.Driver"
The Driver version is postgressql-42.2.5.jar
How do we make a call to PostgreSQL procedure that has multiple output parameters from JDBC?
Please find below the code snippet,
public static void main(String args[]) throws SQLException {
Connection conn = null;
try {
String url = "jdbc:postgresql://<<hostname>>:<<port>>/<<DB>>";
Class.forName("org.postgresql.Driver");
Properties props = new Properties();
props.setProperty("user", "<<user>>");
props.setProperty("password", "<<pass>>");
conn = DriverManager.getConnection(url, props);
CallableStatement cs = conn.prepareCall("call schema.proc1(?,?,?,?)");
cs.setString(1, "test");
cs.setInt(2, 1000);
cs.registerOutParameter(3, Types.INTEGER);
cs.registerOutParameter(4, Types.VARCHAR);
cs.execute();
} catch (Exception e) {
log.error(e);
} finally {
if (conn != null) {
conn.close();
}
}
}
Below is the sample version of the Procedure
Procedure proc1 is (input1 IN varchar2(10),
input2 IN number, output1 OUT number,
output2 OUT varchar2(10)) IS
BEGIN
output2 := input1;
output1 := input2;
END;
Oracle...