How to call a Stored Procedure from JDBC?
Answers were Sorted based on User's Feedback
Answer / rama krishna dwadasi
By using CallableStatement we can call a stored Procedure
from JDBC
CallableStatement:- is an interface available in java.sql
package and is extending PreparedStatement interface.
•It is used to execute stored procedures available in the
database.
•Following is the way to create the CallableStatement object.
a)CallableStatement cs = con.prepareCall(sql);
b)CallableStatement cs = con.prepareCall(sql,int,int);
•One CallableStatement object can be used to invoke one
stored procedure only.
•CallableStatement also provides placeholder mechanism
•Following is the way to invoke the stored procedure.
CallableStatement cs = con.prepareCall(“{call p1 (?,?)}”);
| Is This Answer Correct ? | 3 Yes | 2 No |
Answer / gajendra
We can use CallableStatement interface to call a stored
procedure.Use the following steps.
1. crate the escape syntax like
String sql="{call procname(?,?,?);
2.CallableStatement cst=con.prepareCall(sql);
3.Set the inparameters using setXXX methods like
cst.setInt(1,10);
cst.setString(2,"abc");
4.Register the out parameter
cst.registerOutParameter(1,Types.Float);
5.Submit the statement using
cst.execute();
6. We can get the data from stored procedure using getXXX
methods
| Is This Answer Correct ? | 4 Yes | 4 No |
what is daemon thread and which method is used to create the daemon thread? : Java thread
What is the difference between multitasking and multithreading in Java
0 Answers Sans Pareil IT Services,
what is the difference between ArrayList and Vector
19 Answers KPIT, Sasken, Satyam, Span Infotech, Wipro,
State one difference between a template class and class template.
Why string is not a wrapper class?
what is the use of Clonable,and serializable interface?
Explain when noclassdeffounderror will be raised ?
What is an abstract method in java programming?
Can we have this () and super () together?
what is main difference b/w abstract class and interface
What is a singleton class in Java?
How can we use primitive data types as objects?