|
Informix JDBC Driver complies with the JDBC API specification for sending queries to a database and retrieving the results. The driver supports almost all the methods of the Statement, PreparedStatement, CallableStatement, ResultSet, and ResultSetMetaData interfaces.
The batch update feature is similar to Informix multiple SQL prepare statements. For example, Informix supports the following statement:
The batch update feature in Informix JDBC Driver follows the Sun Microsystems JDBC 2.0 specification, with these exceptions:
The BatchUpdate.java example file shows how to send batch updates to the database server.
The scroll cursors feature in Informix JDBC Driver follows the Sun Microsystems JDBC 2.0 specification, with these exceptions:
The ScrollCursor.java example file shows how to retrieve a result set with a scroll cursor.
This section describes the Informix-specific information you need to know to use Informix JDBC Driver to query an Informix database and process the results.
The Informix JDBC Driver implementation of the Statement.execute() method returns a single ResultSet object. This implementation differs from the JDBC API specification, which states that the method can return multiple ResultSet objects.
Be sure to always explicitly close a Statement, PreparedStatement, and CallableStatement object by calling the appropriate close() method in your Java program when you have finished processing the results of an SQL statement. This closure immediately deallocates the resources that have been allocated to execute your SQL statement. Although the ResultSet.close() method closes the ResultSet object, it does not deallocate the resources allocated to the Statement, PreparedStatement, or CallableStatement objects.
Important: For best results, always call ResultSet.close() and Statement.close() methods to indicate to Informix JDBC Driver that you are done with the statement or result set. Otherwise, your program might not release all its resources on the database server.
Important: The same Statement or ResultSet instance cannot be accessed concurrently across threads. You can, however, share a Connection object between multiple threads.
For example, if one thread executes the Statement.executeQuery() method on a Statement object, and another thread executes the Statement.executeUpdate() method on the same Statement object, the results of both methods are unexpected and depend on which method was executed last.
Similarly, if one thread executes the method ResultSet.next() and another thread executes the same method on the same ResultSet object, the results of both methods are unexpected and depend on which method was executed last.
Example of Sending a Query to an Informix Database
The following example from the SimpleSelect.java program shows how to use the PreparedStatement interface to execute a SELECT statement that has one input parameter:
The program first uses the Connection.prepareStatement() method to prepare the SELECT statement with its single input parameter. It then assigns a value to the parameter using the PreparedStatement.setInt() method and executes the query with the PreparedStatement.executeQuery() method.
The program returns resulting rows in a ResultSet object, through which the program iterates with the ResultSet.next() method. The program retrieves individual column values with the ResultSet.getShort() method, since the data type of the selected column is SMALLINT.
Finally, both the ResultSet and PreparedStatement objects are explicitly closed with the appropriate close() method.
For more information on which getXXX() methods retrieve individual column values, refer to Supported ResultSet.getXXX() Methods.
Valid escape syntax for SQL statements is as follows:
You can put any of this syntax in an SQL statement, as follows:
Everything inside the brackets is converted into a valid Informix SQL statement and returned to the calling function.
The following JDBC API methods are not supported by Informix JDBC Driver and cannot be used in a Java program that connects to an Informix database:
The following JDBC API methods behave differently than specified by the JavaSoft specification: