|bea.com | products | dev2dev | support | askBEA|
|e-docs > WebLogic Server > Programming WebLogic JDBC > Introduction to WebLogic JDBC|
Programming WebLogic JDBC
Introduction to WebLogic JDBC
The following sections provide an overview of the JDBC components and JDBC API:
Overview of JDBC
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).
Using JDBC Drivers with WebLogic Server
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.
Types of JDBC Drivers
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 multitier JDBC drivers makes it easier to adapt purchased components to your DBMS environment and to write more portable code.
Table of WebLogic Server JDBC Drivers
The following table summarizes the drivers that WebLogic Server uses.
Programming WebLogic JDBC (this document)
Administration Console Online Help, "Configuring JDBC Connecttion Pools"
Administration Console Online Help, "Configuring JDBC Connecttion Pools"
Between client and WebLogic Server (connection pool). The RMI driver replaces the deprecated t3 driver. The JTS driver is used in distributed transactions. The Pool and JTS drivers are server-side only.
Programming WebLogic JDBC (this document)
WebLogic Server JDBC Two-Tier Drivers
The following sections describe Type 2 and Type 4 BEA two-tier drivers used with WebLogic Server to connect to the vendor-specific DBMS.
WebLogic jDriver for Oracle
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 jDriver for Microsoft SQL Server
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.
WebLogic Server JDBC Multitier Drivers
The following sections briefly describe the WebLogic multitier JDBC 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 Multitier JDBC Drivers.
WebLogic RMI Driver
The WebLogic RMI driver is a multitier, Type 3, Java Database Connectivity (JDBC) driver that runs in WebLogic Server. You can use the WebLogic RMI driver to connect to a database through a 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. The data source then internally uses the RMI driver. With either method, the WebLogic RMI driver uses the WebLogic Pool and WebLogic JTS drivers internally to get a connection from a connection pool.
Additionally, when configured in a cluster of WebLogic Servers, the WebLogic RMI driver can be used for clustered JDBC, allowing JDBC clients the benefits of load balancing and failover provided by WebLogic Clusters.
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.
WebLogic Pool 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.
WebLogic JTS Driver
The WebLogic JTS driver is a multitier JDBC 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 it avoids two-phase commit. 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.
Sybase jConnect Driver
The two-tier Sybase jConnect Type 4 driver is shipped with your WebLogic Server distribution. You may want to use the latest version of this driver, which is available from the Sybase Web site. For information on using this driver with WebLogic Server, see Using Third-Party Drivers with WebLogic Server.
Oracle Thin Driver
The two-tier 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.
Overview of Connection Pools
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 multitier WebLogic 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 two-tier JDBC driver to make the physical database connections from WebLogic Server to the DBMS. The two-tier driver can be one of the WebLogic jDrivers or a third-party JDBC driver, such as the Sybase jConnect driver or the Oracle Thin Driver. The following table summarizes the advantages to using connection pools.
Making a DBMS connection is very slow. With connection pools, connections are already established and available to users. The alternative is for applications to make their own JDBC connections as needed. A DBMS runs faster with dedicated connections than if it has to handle incoming connection attempts at run time.
If you use the DBMS persistence option with some APIs, such as EJBs, pools are mandatory so that WebLogic Server can control the JDBC connection. This ensures your EJB transactions are committed or rolled back correctly and completely.
This section is an overview of connection pools. For more detailed information, see Configuring and Using Connection Pools.
Using Connection Pools with Server-side Applications
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 two-phase commit transactions, use a TxDataSource from the JNDI tree or use the WebLogic Server JDBC/XA driver, WebLogic jDriver for Oracle/XA. For transactions distributed across multiple servers with one database instance, use a TxDataSource from the JNDI tree or use the JTS driver. BEA recommends that you access connection pools using the JNDI tree and a DataSource object rather than using WebLogic multitier drivers.
Using Connection Pools with Client-side Applications
BEA offers the RMI driver for client-side, multitier JDBC. The RMI driver provides a standards-based approach using the Java 2 Enterprise Edition (J2EE) specifications. For new deployments, BEA recommends that you use a DataSource from the JNDI tree to access database connections rather than the RMI driver.
The WebLogic RMI driver is a Type 3, multitier 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.
Overview of MultiPools
Relevant only in single-server configurations, 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, according to the selected algorithm. MultiPools are not supported multiple-server configurations or with distributed transactions.
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.
Overview of Clustered JDBC
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.
Overview of DataSources
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. Also see the following WebLogic Javadocs:
WebLogic Server uses JDK 1.3.1, which supports JDBC 2.0.
Supported platforms vary by vendor-specific DBMSs and drivers. For current information, see BEA WebLogic Server Platform Support.