Calling procedure in JDBC
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   sandeep_khandelwal
Posted On:   Saturday, April 21, 2001 03:16 PM

I've created procedures in MS-SQL7.0 andI need to call them through my front end. How do I do this??

Re: Calling procedure in JDBC

Posted By:   Luigi_Viggiano  
Posted On:   Saturday, April 21, 2001 04:44 PM

You can use JDBC and Java to call a database stored procedure.

First you must create a CallableStatement object from the Connection object, then use appropriate method on the CallableStatement instance:

...
Connection conn = ...
CallableStatement cs = conn.prepareCall("{call STORED_PROCEDURE}");
ResultSet rs = cs.executeQuery();
...

In the upon example, executeQuery has been used pretending that STORED_PROCEDURE returns a ResultSet, but if your stored procedure is just an update or a DDL command, the executeUpdate method is the best choice.

The execute method must be used if your stored procedure run multiple SQL statements, that obtains multiple resultsets, and get multiple updated row count, etc.


As CallableStatement is a sub-interface of PreparedStatement, its instances can be used with parameters.

CallableStatement has lot of methods you shall know to use it successfully, please refer to CallableStatement API doc for complete informations.

About | Sitemap | Contact