Oracle Exams Exams of Oracle,Oracle Certification Exam,Using the CallableStatement Object Executing Statements – JDBC Applications and Design Considerations

Executing Statements – JDBC Applications and Design Considerations



4.2.3   Executing Statements

To successfully execute an appropriate Statement object to perform Oracle statements, the following operational sequence should be followed:

1) Creating a Statement object based on the requirements of the data actions

2) Calling the appropriate execution method to run the Oracle statements

In essence, the Statement object is used for executing a static Oracle statement and returning the results stored in a ResultSet object.

4.2.3.1   Overview of Statement Objects and Their Execution Methods

By using the Connection object, three separate statement objects can be created:

  • Statement object
  • PreparedStatement object
  • CallableStatement object

The Statement object is used to execute static Oracle queries. So-called static statements do not include any IN or OUT parameters in the query string and do not contain any parameters pass-ing to or from the database.

The Statement interface contains more than 18 methods, and Table 4.4 lists the 10 most popu-lar methods.

Among these ten methods in the Statement interface, three execution methods, execute-Query(), executeUpdate() and execute(), and the getResultSet() method are often used in Java database applications.

PreparedStatement is a subclass of Statement, and it is mainly used to execute dynamic Oracle queries that involve the IN parameter. These kinds of statements can be pre-parsed and pre-compiled by the database and therefore have faster processing speed and lower running loads for the database server.

The PreparedStatement interface contains more than 20 methods, and Table 4.5 lists the

17 most popular methods.

It can be seen from Table 4.5 that three execution methods, execute(), executeQuery() and executeUpdate(), look like duplicates of those methods defined in the Statement interface. However, a significant difference is that all three of these methods defined in the Statement interface have their query strings as an argument when they are executed, which means that the Oracle state-ments have to be defined in those query strings and should be passed into the database as the argu-ments of those methods. In contrast, all three methods defined in the PreparedStatement interface have no argument to be passed into the database when they are executed. This means that the Oracle statements have been built and passed into the database by using the PreparedStatement object before these three methods are executed.

Two methods belong to the getters that are used to retrieve the metadata for the ResultSet and the ParameterMetaData objects. Both methods are very useful when the developer wants to get more detailed structure and property information about a returned ResultSet or ParameterMetaData object.

More than ten methods defined in the PreparedStatement interface are setter methods, which means that these methods are used to set up an appropriate value to an input parameter with different data types. These methods are especially useful when a dynamic query is built with one or more dynamic input parameters that need to be determined in the Oracle statements.

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post