what r callable statement and give their proper use

Answer Posted / qamrun nisa

CallableStatement is invoked to call stored procedure.
The basic steps are:

1. Invoke the Connection.prepareCall method to create a
CallableStatement object.
2. Invoke the CallableStatement.setXXX methods to pass
values to the input (IN) parameters.
3. Invoke the CallableStatement.registerOutParameter
method to indicate which parameters are output-only (OUT)
parameters, or input and output (INOUT) parameters.
4. Invoke one of the following methods to call the stored
procedure:

CallableStatement.executeUpdate
Invoke this method if the stored procedure does
not return result sets.
CallableStatement.executeQuery
Invoke this method if the stored procedure returns
one result set.
CallableStatement.execute
Invoke this method if the stored procedure returns
multiple result sets.

5. If the stored procedure returns result sets, retrieve
the result sets. See Retrieve multiple result sets from a
stored procedure in a JDBC application.
6. Invoke the CallableStatement.getXXX methods to
retrieve values from the OUT parameters or INOUT parameters.
7. Invoke the CallableStatement.close method to close the
CallableStatement object when you have finished using that
object.

The following code illustrates calling a stored procedure
that has one input parameter, four output parameters, and no
returned ResultSets. The numbers to the right of selected
statements correspond to the previously-described steps.

int ifcaret;
int ifcareas;
int xsbytes;
String errbuff;
Connection con;
CallableStatement cstmt;
ResultSet rs;
...
cstmt = con.prepareCall("CALL DSN8.DSN8ED2(?,?,?,?,?)");
1
// Create a
CallableStatement object
cstmt.setString (1, "DISPLAY THREAD(*)");
2
// Set input parameter
(DB2 command)
cstmt.registerOutParameter (2, Types.INTEGER);
3
// Register output parameters
cstmt.registerOutParameter (3, Types.INTEGER);
cstmt.registerOutParameter (4, Types.INTEGER);
cstmt.registerOutParameter (5, Types.VARCHAR);
cstmt.executeUpdate(); // Call the stored
procedure 4
ifcaret = cstmt.getInt(2); // Get the output
parameter values 6
ifcareas = cstmt.getInt(3);
xsbytes = cstmt.getInt(4);
errbuff = cstmt.getString(5);
cstmt.close();

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can static methods access instance variables in java?

580


What is better - 'bit-shift a value' or 'multiply by 2'?

706


What is a substitution variable?

569


What is singleton class in ruby?

566


Can a private method of a superclass be declared within a subclass?

537






How to reverse a string in java?

532


What is the difference between public, private, protected, and friend access?

580


How do you reverse a list?

558


Will the compiler creates a default constructor if I have a parameterized constructor in the class?

589


What is difference between hashset and hashmap in java?

470


Why object class is super class for every class in java?

583


What exceptions occur during serialization?

612


Where import statement is used in a java program?

612


What is the purpose of tostring() method in java?

560


Can you have two constructors in java?

507