I am calling a postgres stored procedure from spring boot application which has 1 IN parameter of type text and 1 INOUT parameter of type refcursor. How to call this procedure from springboot application other than CallableStatement.
public class CallProc {
public static void main(String[] args) throws ClassNotFoundException, java.sql.SQLException {
Class.forName("org.postgresql.Driver");
String url = "jdbc:postgresql://azure.com/test";
Properties props = new Properties();
props.setProperty("user","test");
props.setProperty("password","test");
props.setProperty("ssl","true");
props.setProperty("escapeSyntaxCallMode", "callIfNoReturn");
Connection conn = DriverManager.getConnection(url, props);
// need a transaction
conn.setAutoCommit(false);
java.sql.CallableStatement callableStatement =
conn.prepareCall("{call myProc(?, ?)}");
callableStatement.setString(1, "user");
callableStatement.setObject(2, null);
callableStatement.registerOutParameter(2, java.sql.Types.REF_CURSOR);
callableStatement.execute();
java.sql.ResultSet rs =
(java.sql.ResultSet) callableStatement.getObject(2);
while (rs.next())
System.out.println(rs.getInt(1));
rs.close();
conn.commit();
conn.close();
}
}
and my procedure definition is like this,
CREATE OR REPLACE PROCEDURE myapp.MyProc(
in_user_id TEXT,
INOUT user_roles refcursor)
language plpgsql
AS $BODY$
DECLARE
DERIVED USER_ID VARCHAR(50);
BEGIN
//body
...
//
END
$BODY$
Thanks