Saturday, 1 September 2012

How do we call a stored procedure from JDBC?


• The foremost step is to create a CallableStatement object. 

• With the Statement and PreparedStatement object ,it is done with an open
Connection object. 

• A CallableStatement object contains a call to a stored procedure.

Code:

CallableStatement cs = con.prepareCall("{call SHOW_Sales}");
ResultSet rs = cs.executeQuery();


or


• PL/SQL stored procedures are called from the JDBC programs by creating the prepareCall() in the Connection object. 

• A call to the method prepareCall() carries out variable bind parameters as input parameters, output variables & makes an object instance of the CallableStatement class.

• The following line of code implies this:

Callable Statement stproc_ stmt = conn.prepareCall("{call procname(?,?,?)}");

where conn is the instance of the Connection class.

No comments:

Post a Comment