CallableStatement cs = conn.prepareCall("{call get_customer_info(?, ?)}"); cs.setInt(1, customerId); cs.registerOutParameter(2, java.sql.Types.INTEGER); ResultSet rs = cs.executeQuery(); int errorCode = cs.getInt(2);
CallableStatement cs = conn.prepareCall("{call get_order_info(?)}"); cs.setInt(1, orderId); boolean hasResults = cs.execute(); while (hasResults) { ResultSet rs = cs.getResultSet(); // do something with the result set hasResults = cs.getMoreResults(); }In this example, we create a CallableStatement to call a stored procedure "get_order_info" that takes an input parameter (order ID) and returns multiple result sets. We set the input parameter using the setInt() method and execute the query using execute(). Then we loop through the result sets using getResultSet() and getMoreResults(). To use CallableStatement, we need to import the java.sql package library.