Oracle 5.0 Reference Manual page 2109

Table of Contents

Advertisement

Example 20.2. Connector/J: Using java.sql.Statement to execute a
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
// assume that conn is an already created JDBC connection (see previous examples)
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery("SELECT foo FROM bar");
// or alternatively, if you don't know ahead of time that
// the query will be a SELECT...
if (stmt.execute("SELECT foo FROM bar")) {
rs = stmt.getResultSet();
}
// Now do something with the ResultSet ....
}
catch (SQLException ex){
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
finally {
// it is a good idea to release
// resources in a finally{} block
// in reverse-order of their creation
// if they are no-longer needed
if (rs != null) {
try {
} catch (SQLException sqlEx) { } // ignore
rs = null;
}
if (stmt != null) {
try {
} catch (SQLException sqlEx) { } // ignore
stmt = null;
}
}
20.3.6.3. Using JDBC
Starting with MySQL server version 5.0 when used with Connector/J 3.1.1 or newer, the
java.sql.CallableStatement
getParameterMetaData()
For more information on MySQL stored procedures, please refer to
stored-routines.html.
Connector/J exposes stored procedure functionality through JDBC's
rs.close();
stmt.close();
CallableStatements
interface is fully implemented with the exception of the
method.
Note
Current versions of MySQL server do not return enough information for the
JDBC driver to provide result set metadata for callable statements. This means
JDBC Concepts
to Execute Stored Procedures
2089
query
SELECT
http://dev.mysql.com/doc/mysql/en/
CallableStatement
interface.

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents