A stored procedure is a database procedure, similar to a procedure in other programming languages, which is contained within the database itself. In SQL Server, stored procedures can be created by using Transact-SQL, or by using the common language runtime (CLR) and one of the Visual Studio 2005 programming languages such as Visual Basic or C#. Generally, SQL Server stored procedures can do the following:

Note: For more information about SQL Server stored procedures, see "Understanding Stored Procedures" in SQL Server Books Online.

To work with data in a SQL Server database by using a stored procedure, the Microsoft SQL Server 2005 JDBC Driver provides the SQLServerStatement, SQLServerPreparedStatement, and SQLServerCallableStatement classes. Which class you use depends on whether IN (input) or OUT (output) parameters are required by the stored procedure. If the stored procedure requires no IN or OUT parameters, you can use the SQLServerStatement class; if the stored procedure will be called multiple times, or requires only IN parameters, you can use the SQLServerPreparedStatement class. If the stored procedure requires both IN and OUT parameters, you should use the SQLServerCallableStatement class. It is only when the stored procedure requires OUT parameters that you will need the overhead of using the SQLServerCallableStatement class.

Note: Stored procedures can also return update counts and multiple result sets. For more information, see Using a Stored Procedure with an Update Count and Using Multiple Result Sets.

When you use the JDBC driver to call a stored procedure with parameters, you must use the call SQL escape sequence together with the prepareCall method of the SQLServerConnection class. The complete syntax for the call escape sequence is as follows:

{[?=]call procedure-name[([parameter][,[parameter]]...)]}

Note: For more information about the call and other SQL escape sequences, see Using SQL Escape Sequences.

The topics in this section describe the ways that you can call SQL Server stored procedures by using the JDBC driver and the call SQL escape sequence.

In This Section

Topic Description

Using a Stored Procedure with No Parameters

Describes how to use the JDBC driver to run stored procedures that contain no input or output parameters.

Using a Stored Procedure with Input Parameters

Describes how to use the JDBC driver to run stored procedures that contain input parameters.

Using a Stored Procedure with Output Parameters

Describes how to use the JDBC driver to run stored procedures that contain output parameters.

Using a Stored Procedure with a Return Status

Describes how to use the JDBC driver to run stored procedures that contain return status values.

Using a Stored Procedure with an Update Count

Describes how to use the JDBC driver to run stored procedures that return update counts.

See Also