Java examples for JDBC:Stored Procedure
Stored Procedure accepts an IN parameter and returns an integer value.
import java.sql.CallableStatement; import java.sql.Connection; public class Main { public static void main(String[] args) { try {// w w w.java2 s . c o m Connection conn = null;//JDBCUtil.getConnection(); String sql = "{? = call get_employee_count(?)}"; CallableStatement cstmt = conn.prepareCall(sql); // Register the first placeholder - the return value as an OUT parameter cstmt.registerOutParameter(1, java.sql.Types.INTEGER); // Set the value for dept_id parameter at index 2 cstmt.setInt(2, 1001); // Execute the stored procedure cstmt.execute(); // Read the returned value - our first OUT parameter has an index of 1 int employeeCount = cstmt.getInt(1); System.out.println("Employee Count is " + employeeCount); } catch (Exception e) { e.printStackTrace(); } } }