Table of Contents Previous Next


4 Using the Advanced Server JDBC Connector with Java applications : 4.3 Executing SQL Statements through Statement Objects

A Statement object sends SQL statements to a database. There are three kinds of Statement objects. Each is specialized to send a particular type of SQL statement:
A Statement object is used to execute a simple SQL statement with no parameters.
A PreparedStatement object is used to execute a pre-compiled SQL statement with or without IN parameters.
A CallableStatement object is used to execute a call to a database stored procedure.
You must construct a Statement object before executing an SQL statement. The Statement object offers a way to send a SQL statement to the server (and gain access to the result set). Each Statement object belongs to a Connection; use the createStatement() method to ask the Connection to create the Statement object.
A Statement object defines several methods to execute different types of SQL statements. In the sample application, the executeQuery() method executes a SELECT statement:
The executeQuery() method expects a single argument: the SQL statement that you want to execute. executeQuery() returns data from the query in a ResultSet object. If the server encounters an error while executing the SQL statement provided, it throws an SQLException (and does not return a ResultSet).

4 Using the Advanced Server JDBC Connector with Java applications : 4.3 Executing SQL Statements through Statement Objects

Table of Contents Previous Next