Answer Posted / kuldeep raaj sharma
The Statement is an interface and its subclasses are
PreparedStatement and CallableStatement.
The Statement interface defines methods for executing SQL
statements that do not contain parameter markers. The
PreparedStatement interface adds methods for setting input
parameters, and the CallableStatement interface adds
methods for retrieving output parameter values returned
from stored procedures.
The CallableStatement interface extends PreparedStatement
with methods for executing and retrieving results from
stored procedures.
Creating a CallableStatement Object
As with Statement and PreparedStatement objects,
CallableStatement objects are created by Connection
objects. CODE EXAMPLE 13-18 shows the creation of a
CallableStatement object for calling the stored
procedure ‘validate’, which has a return parameter and two
other parameters.
CallableStatement cstmt = conn.prepareCall(
“{? = call validate(?, ?)}”);
Setting Parameters
CallableStatement objects may take three types of
parameters: IN, OUT, and
INOUT. The parameter can be specified as either an ordinal
parameter or a named
parameter. A value must be set for each parameter marker in
the statement.
The number, type, and attributes of parameters to a stored
procedure can be
determined using the DatabaseMetaData method
getProcedureColumns.
Parameter ordinals, which are integers passed to the
approriate setter method, refer to the parameter markers
("?") in the statement, starting at one. Literal parameter
values in the statement do not increment the ordinal value
of the parameter markers.
In CODE EXAMPLE the two parameter markers have the ordinal
values 1 and 2.
CallableStatement cstmt = con.prepareCall(
"{CALL PROC(?, "Literal_Value", ?)}");
cstmt.setString(1, "First");
cstmt.setString(2, "Third");
Is This Answer Correct ? | 4 Yes | 1 No |
Post New Answer View All Answers
How do I check in my code whether a maximum limit of database connections have been reached?
What is the difference between setmaxrows(int) and setfetchsize(int)?
What is the limitation of PreparedStatement and how to overcome it?
Explain how to make updates to the updatable resultsets.
What is com mysql jdbc driver?
What is the return type of execute, executequery and executeupdate?
What is the use of jdbc api?
How can you know about drivers and database information ?
What is an odbc driver?
What are temp tables ?
Explain the importance of drivermanager.
What does the connection object represents?
What is JDBC Transaction Management and why do we need it?
What is the use of dialect?
There is a method getColumnCount in the JDBC API. Is there a similar method to find the number of rows in a result set?