Using the JDBC Interfaces

From InterBase

Go Up to Developing InterClient Programs

The JDBC API is a set of Java interfaces that allow database applications to open connections to a database, execute SQL statements, and process the results. These include:

java.sql.DriverManager

Loads the specific drivers and supports creating new database connections.

java.sql.Connection

Represents a connection to a specific database.

java.sql.Statement

Allows the application to execute a SQL statement.

java.sql.PreparedStatement

Represents a pre-compiled SQL statement.

The following methods have been implemented:

  • Public void setObject (int parameterIndex, Object x) now works when parameter x is of type java.io.Inputstream.
  • All variations of the setCharacterStream () method are implemented.
  • All variations of the setAsciiStream() and setBinaryStream() methods are implemented.
  • All variations of setBlob () and setClob() methods are implemented.
  • The isClosed() method is implemented.

java.sql.CallableStatement

Represents a call to a stored procedure in the database.

java.sql.ResultSet

Controls access to the rows resulting from a statement execution.

The following methods have been implemented:

  • All variations of the getCharacterStream () method are implemented.
  • All variations of the getBlob () and getClob() methods are implemented.

JDBC interfaces

Importing the InterClient Classes

The InterClient classes provide the code that actually implements the JDBC API. The java.sql package defines the standard JDBC API interfaces. Importing this package allows you to reference all of the classes in the java.sql interface without first typing the “java.sql” prefix. For clarity's sake, this document prefixes all class names with “java.sql,” but it isn't necessary if you import the package. You can import this package with the following line:

import java.sql.*;

The DriverManager Class

The DriverManager class is part of the java.sql package. The JDBC framework supports multiple database drivers. The DriverManager manages all JDBC drivers that are loaded on a system; it tries to load as many drivers as it can find. For each connection request, it locates a driver to connect to the target database URL. The DriverManager also enforces security measures defined by the JDBC specification.

The Driver Class

Each database driver must provide a Driver class that implements the java.sql.Driver interface. The interbase.interclient.Driver class is an all-Java implementation of a JDBC driver that is specific to InterBase. The interbase.interclient package supports most of the JDBC classes and methods plus some added extensions that are not part of the JDBC API.

To access an InterBase database, the InterClient driver communicates via a TCP/IP connection with the InterBase server. InterBase processes the SQL statements and passes the results back to the InterClient driver.

Multithreading

Any JDBC driver must comply with the JDBC standard for multithreading, which requires that all operations on Java objects be able to handle concurrent execution.

For a given connection, several threads must be able to safely call the same object simultaneously. The InterClient driver is thread safe. For example, your application can execute two or more statements over the same connection concurrently, and process both result sets concurrently, without generating errors or ambiguous results.

The JDBC Connection Class

After instantiating a Driver object, you can open a connection to the database when DriverManager gives you a Connection object. A database driver can manage many connection objects.

The Connection object establishes and manages the connection to your particular database. Within a given connection, you can execute SQL statements and receive the result sets.

The java.sql.Connection interface represents a connection to a particular database. The JDBC specification allows a single application to support multiple connections to one or more databases, using one or more database drivers. When you establish your connection using this class, the DriverManager selects an appropriate driver from those loaded based on the subprotocol specified in the URL, which is passed as a connection parameter.


Advance To: