Mega Code Archive

 
Categories / Java / Database SQL JDBC
 

Call stored procedure

import java.sql.CallableStatement; import java.sql.Connection; import java.sql.Types; public class Main {   public static void main(String[] argv) throws Exception {     Connection conn = null;     String query = "begin proc(?,?,?); end;";     CallableStatement cs = conn.prepareCall(query);     cs.setString(1, "string parameter");     cs.setInt(2, 1);     cs.registerOutParameter(2, Types.INTEGER);     cs.registerOutParameter(3, Types.INTEGER);     cs.execute();     int parm2 = cs.getInt(2); // get the result from OUTPUT #2     int parm3 = cs.getInt(3); // get the result from OUTPUT #3   } }