Using the JDBC Interfaces
Go Up to Developing InterClient Programs
Contents
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:
|
Loads the specific drivers and supports creating new database connections. |
|
Represents a connection to a specific database. |
|
Allows the application to execute a SQL statement. |
|
Represents a pre-compiled SQL statement. The following methods have been implemented:
|
|
Represents a call to a stored procedure in the database. |
|
Controls access to the rows resulting from a statement execution. The following methods have been implemented:
|
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.