The java.sql package provides the CallableStatement interface which is used to execute stored procedures with input and output parameters. One of the input parameter datatypes is an int, which can be set using the setInt() method.
Example 1:
// Assuming the stored procedure takes an int parameter and returns a resultset CallableStatement cs = con.prepareCall("{ call my_stored_proc(?) }"); cs.setInt(1, 15); // sets the input parameter to 15 ResultSet rs = cs.executeQuery();
Example 2:
// Assuming the stored procedure takes two int parameters and returns an int value CallableStatement cs = con.prepareCall("{ ? = call my_other_stored_proc(?, ?) }"); cs.registerOutParameter(1, Types.INTEGER); // registers the return value as an int cs.setInt(2, 10); // sets the first input parameter to 10 cs.setInt(3, 20); // sets the second input parameter to 20 cs.execute(); int result = cs.getInt(1);
In both examples, we use the CallableStatement's setInt() method to set input parameters before executing the stored procedure, passing in the parameter index and the int value to be set. Example 2 also registers the expected return value as an int using registerOutParameter() and retrieves that value using getInt() after executing the procedure.
The java.sql package is part of the Java Standard Edition (SE) library.
Java CallableStatement.setInt - 30 examples found. These are the top rated real world Java examples of java.sql.CallableStatement.setInt extracted from open source projects. You can rate examples to help us improve the quality of examples.