By: Watson in JDBC Tutorials on 2007年10月13日 [フレーム]
JDBC allows you to call a database stored procedure from an application
written in the Java programming language. The first step is to create a CallableStatement
object. As with Statement and PreparedStatement
objects, this is done with an open Connection object. A callableStatement
object contains a call to a stored procedure; it does not contain the stored
procedure itself. The first line of code below creates a call to the stored
procedure SHOW_SUPPLIERS using the connection con.
The part that is enclosed in curly braces is the escape syntax for stored
procedures. When the driver encounters "{call SHOW_SUPPLIERS}",
it will translate this escape syntax into the native SQL used by the database
to call the stored procedure named SHOW_SUPPLIERS.
CallableStatement cs = con.prepareCall("{call SHOW_SUPPLIERS}");
ResultSet rs = cs.executeQuery();
The ResultSet rs will be similar to the
following:
SUP_NAME COF_NAME ---------------- ----------------------- Acme, Inc. Colombian Acme, Inc. Colombian_Decaf Superior Coffee French_Roast Superior Coffee French_Roast_Decaf The High Ground Espresso
Note that the method used to execute cs is executeQuery
because cs calls a stored procedure that contains one query and
thus produces one result set. If the procedure had contained one update or one
DDL statement, the method executeUpdate would have been the one
to use. It is sometimes the case, however, that a stored procedure contains
more than one SQL statement, in which case it will produce more than one
result set, more than one update count, or some combination of result sets and
update counts. In this case, where there are multiple results, the method execute
should be used to execute the CallableStatement .
The class CallableStatement is a subclass of PreparedStatement,
so a CallableStatement object can take input parameters just as a
PreparedStatement object can. In addition, a CallableStatement
object can take output parameters, or parameters that are for both input and
output. INOUT parameters and the method execute are used rarely.
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
This policy is subject to change at any time and without notice.
These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:
Failure to comply with these rules may result in being banned from submitting further comments.
These terms and conditions are subject to change at any time and without notice.
Most Viewed Articles (in JDBC )
Data Access Technologies in Java
Calling a Stored Procedure from JDBC in Java
What is Referential Integrity in databases?
JDBC and Tomcat context settings
TEXT datatype SPLIT in MSSQL - to solve the 8000 limit set by varchar
setSavepoint and releaseSavepoint Example in Java
java.lang.NoClassDefFoundError and java.lang.NoSuchMethodError
Handling CSV in Stored Procedures
How connection pooling works in Java and JDBC
Using JDBC to connect to MySQL from Java Program
Using the DriverManager Class vs Using a DataSource Object for a connection
Latest Articles (in JDBC)
Data Access Technologies in Java
JDBC and Tomcat context settings
TEXT datatype SPLIT in MSSQL - to solve the 8000 limit set by varchar
What is Referential Integrity in databases?
Handling CSV in Stored Procedures
java.lang.NoClassDefFoundError and java.lang.NoSuchMethodError
Calling a Stored Procedure from JDBC in Java
setSavepoint and releaseSavepoint Example in Java
Result Sets, Cursors and Transactions in SQL
Stored Procedures example in SQL
Using the DriverManager Class vs Using a DataSource Object for a connection
Data Access Technologies in Java
JDBC and Tomcat context settings
TEXT datatype SPLIT in MSSQL - to solve the 8000 limit set by varchar
What is Referential Integrity in databases?
Handling CSV in Stored Procedures
java.lang.NoClassDefFoundError and java.lang.NoSuchMethodError
Calling a Stored Procedure from JDBC in Java
setSavepoint and releaseSavepoint Example in Java
Result Sets, Cursors and Transactions in SQL
Stored Procedures example in SQL
Using the DriverManager Class vs Using a DataSource Object for a connection
© 2023 Java-samples.com
Tutorial Archive: Data Science React Native Android AJAX ASP.net C C++ C# Cocoa Cloud Computing EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Trends WebServices XML Office 365 Hibernate
Latest Tutorials on: Data Science React Native Android AJAX ASP.net C Cocoa C++ C# EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Cloud Computing WebServices XML Office 365 Hibernate