Programming WebLogic JDBC
The following sections provide an overview of the JDBC components and JDBC API:
Java Database Connectivity (JDBC) is a standard Java API that consists of a set of classes and interfaces written in the Java programming language. Application, tool, and database developers use JDBC to write database applications and execute SQL statements.
JDBC is a low-level interface, which means that you use it to invoke (or call) SQL commands directly. In addition, JDBC is a base upon which to build higher-level interfaces and tools, such as Java Message Service (JMS) and Enterprise Java Beans (EJBs).
JDBC drivers implement the interfaces and classes of the JDBC API. The following sections describe the JDBC driver options that you can use with WebLogic Server.
WebLogic Server uses the following types of JDBC drivers that work in conjunction with each other to provide database access:
The middle tier architecture of WebLogic Server, including data sources and connection pools, allows you to manage database resources centrally in WebLogic Server. The vendor-neutral wrapper drivers makes it easier to adapt purchased components to your DBMS environment and to write more portable code.
The following table summarizes the drivers that WebLogic Server uses.
Between WebLogic Server and DBMS in local and distributed transactions. |
Programming WebLogic JDBC (this document) Administration Console Online Help, "Configuring JDBC Connection Pools" |
|
Between WebLogic Server and DBMS in local and distributed transactions. Note: The WebLogic jDrivers for Microsoft SQL Server supports local transactions only. |
Programming WebLogic JDBC (this document) Administration Console Online Help, "Configuring JDBC Connection Pools" |
|
Between an external client and WebLogic Server (connection pool). |
Programming WebLogic JDBC (this document) |
When deciding which JDBC driver to use to connect to a database, you should try drivers from various vendors in your environment. In general, JDBC driver performance is dependent on many factors, especially the SQL code used in applications and the JDBC driver implementation.
For information about supported JDBC drivers, see "Supported Database Configurations" in Supported Configurations for WebLogic Platform 8.1.
The following sections describe Type 2 and Type 4 JDBC drivers from BEA used with WebLogic Server to connect to the vendor-specific DBMS.
BEA's WebLogic jDriver for Oracle is included with the WebLogic Server distribution. This driver requires an Oracle client installation. The WebLogic jDriver for Oracle XA driver extends the WebLogic jDriver for Oracle for distributed transactions. For additional information, see Using WebLogic jDriver for Oracle.
WebLogic Server 8.1 SP1 includes a new JDBC driver from BEA for connecting to a Microsoft SQL Server database. The BEA WebLogic Type 4 JDBC MS SQL Server driver replaces the WebLogic jDriver for Microsoft SQL Server, which is deprecated. The new driver offers JDBC 3.0 compliance, support for some JDBC 2.0 extensions, and better performance. BEA recommends that you use the new BEA WebLogic Type 4 JDBC MS SQL Server driver in place of the WebLogic jDriver for Microsoft SQL Server.
For more information, see BEA WebLogic Type 4 JDBC Drivers.
BEA's WebLogic jDriver for Microsoft SQL Server, included in the WebLogic Server distribution, is a pure-Java, Type 4 JDBC driver that provides connectivity to Microsoft SQL Server. For more information, see Configuring and Using WebLogic jDriver for MS SQL Server.
The following sections briefly describe the WebLogic wrapper drivers that provide database access to applications. You can use these drivers in server-side applications (also in client applications for the RMI driver), however BEA recommends that you look up a data source from the JNDI tree to get a database connection.
For more details about using these drivers, see Using WebLogic Wrapper Drivers.
The WebLogic RMI driver is a Type 3 JDBC driver that runs in WebLogic Server. You can use the WebLogic RMI driver in a remote client application to connect to a database through a WebLogic Server connection pool, however, this is not the recommended method. BEA recommends that you look up a data source on the JNDI tree to get a database connection from a connection pool. For requests from external clients, the data source then internally uses the RMI driver, if necessary.
You can use the WebLogic RMI driver with server-side or client applications.
For more details about using the WebLogic RMI driver, see Using the WebLogic RMI Driver.
The WebLogic Pool driver enables utilization of connection pools from server-side applications such as HTTP servlets or EJBs. You can use it directly in server-side applications, but BEA recommends that you use a data source through a JNDI look-up to get a connection from a connection pool. Data sources in WebLogic Server use the WebLogic Pool driver internally to get connections from a connection pool.
For information about using the Pool driver, see Accessing Databases in Programming Tasks in Programming WebLogic HTTP Servlets.
The WebLogic JTS driver is a wrapper driver that is similar to the WebLogic Pool Driver, but is used in distributed transactions across multiple servers with one database instance. The JTS driver is more efficient than the WebLogic jDriver for Oracle XA driver when working with only one database instance because calls from the transaction manager to start and end work with this branch of the transaction (XAResource.start()
and XAResource.end()
) do not require communication with the database (they are no-ops).
This driver is for use with server-side applications only.
For more details about using the WebLogic JTS driver, see Using the WebLogic JTS Driver.
WebLogic Server works with third-party JDBC drivers that meet the following requirements:
You typically use these drivers when configuring WebLogic Server to create physical database connections in a connection pool.
The Oracle Thin Type 4 driver bundled with WebLogic Server provides connectivity from WebLogic Server to an Oracle DBMS. You may want to use the latest version of the Oracle Thin driver, which is available from the Oracle Web site. For information on using this driver with WebLogic Server, see Using Third-Party Drivers with WebLogic Server.
In WebLogic Server, you can configure connection pools that provide ready-to-use pools of connections to your DBMS. Client and server-side applications can utilize connections from a connection pool through a DataSource on the JNDI tree (the preferred method) or by using a WebLogic wrapper driver. When finished with a connection, applications return the connection to the connection pool.
Figure 1-1 WebLogic Server Connection Pool Architecture
When the connection pool starts up, it creates a specified number of physical database connections. By establishing connections at start-up, the connection pool eliminates the overhead of creating a database connection for each application.
Connection pools require a JDBC driver to make the physical database connections from WebLogic Server to the DBMS. The JDBC driver can be one of the WebLogic jDrivers or a third-party JDBC driver, such as the Oracle Thin Driver. The following table summarizes the advantages to using connection pools.
This section is an overview of connection pools. For more detailed information, see Configuring and Using Connection Pools.
For database access from server-side applications, such as HTTP servlets, use a DataSource from the Java Naming and Directory Interface (JNDI) tree or use the WebLogic Pool driver. For distributed transactions, use a TxDataSource from the JNDI tree. For transactions distributed across multiple servers within a single WebLogic domain with one database instance, use a TxDataSource from the JNDI tree or use the JTS driver. Note that BEA recommends that you access connection pools using the JNDI tree and a DataSource object rather than using WebLogic wrapper drivers.
Note: For new deployments, BEA recommends that you use a DataSource from the JNDI tree to access database connections rather than the RMI driver.
BEA offers the RMI driver for client-side JDBC. The RMI driver provides a standards-based approach using the Java 2 Enterprise Edition (J2EE) specifications.
The WebLogic RMI driver is a Type 3 JDBC driver that uses RMI and a DataSource object to create database connections. This driver also provides for clustered JDBC, leveraging the load balancing and failover features of WebLogic Server clusters. You can define DataSource objects to enable transactional support or not.
JDBC MultiPools are "pools of connection pools" that you can set up according to either a high availability or load balancing algorithm. You use a MultiPool in the same manner that you use a connection pool. When an application requests a connection, the MultiPool determines which connection pool will provide a connection, based on the selected algorithm.
You can choose one of the following algorithm options for each MultiPool in your WebLogic Server configuration:
For more information, see Configuring and Using MultiPools.
WebLogic Server allows you to cluster JDBC objects, including data sources, connection pools and MultiPools, to improve the availability of cluster-hosted applications. Each JDBC object you configure for your cluster must exist on each managed server in the cluster—when you configure the JDBC objects, target them to the cluster.
For information about JDBC objects in a clustered environment, see "JDBC Connections" in Using WebLogic Server Clusters.
Client- and server-side JDBC applications can obtain a DBMS connection using a DataSource. A DataSource is an interface between an application and the connection pool. Each data source (such as a DBMS instance) requires a separate DataSource object, which may be implemented as a DataSource class that supports distributed transactions. For more information, see Configuring and Using DataSources.
To create a JDBC application, use the java.sql API to create the class objects necessary to establish a connection with a data source, to send queries and update statements to the data source, and to process the results. For a complete description of all JDBC interfaces, see the standard JDBC interfaces at java.sql Javadoc. See Configuring and Using Connection Pools. Also see the following WebLogic Javadocs:
WebLogic Server uses a Java 2 SDK 1.4.1, which supports JDBC 2.0.
Supported platforms vary by vendor-specific DBMSs and drivers. For current information, see BEA WebLogic Supported Configurations.