what r callable statement and give their proper use

Answers were Sorted based on User's Feedback



what r callable statement and give their proper use..

Answer / prajal

Callable statement (java.sql.CallableStatement) are used for
calling a Stored Procedure.

Syntax is as below-
//prepare a procedure call
String procedureCall="call testProcedure(:1,:2,:3)";
//prepare a callable statement

CallableStatement
cStmt=connectionObject.prepareCall(procedureCall);

// Set the Input Parameters to the procedure
cStmt.setInt(1, testID);
cStmt.setInt(2, testNumber);

// Register Output Parameters
cStmt.registerOutParameter(3, Types.VARCHAR);

// Execute the Callable Statement
cStmt.execute();

// Resulting Values from the Callable Statement is assigned
to the Message variable
String message = cStmt.getString(3);

Is This Answer Correct ?    5 Yes 0 No

what r callable statement and give their proper use..

Answer / 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

More Core Java Interview Questions

What about instanceof operator in java?

0 Answers  


Why java is considered dynamic?

0 Answers  


What advantage does an entity bean have over a sessin bean?

3 Answers   Adobe,


What is an interface in java?

0 Answers  


What is the use of StringTokenizer class?

0 Answers   Hexaware, Virtusa,






What will happen to the exception object after exception handling?

0 Answers  


What is immutable state?

0 Answers  


What is charat java?

0 Answers  


What is polymorphism and what are the types of it?

0 Answers  


What are the features of junit?

0 Answers  


can anyone explain me the concept of autoboxing?

3 Answers  


What do you understand by the term singleton?

0 Answers  


Categories