This article describes the configuration of various and JDBC related functions in BEA WebLogic 8.1 Server. Although we used Oracle 8.1.7 as our sample database management system (DBMS), as long as other relational databases provide a connection through JDBC, you can easily transfer general concepts to these databases.
JDBC is a standard Java API, almost all J2EE applications that need to access the database directly or indirectly. In BEA WebLogic 8.1, configuring the JDBC connection includes creating and configuring two main artifacts - JDBC connecting pools and data sources. The other secondary workpiece is related to these two main workpieces, such as multi-pool or data source factory.
Connect pool or multi-pool? Before discussing how to create and configure the connection pool, we need to briefly see the reasons for the use of the connection pool. If you do not use the JDBC connection pool to access the database, in order to establish a connection to the database, you will need to make the following steps:
Load the JDBC driver class. Create an instance of the JDBC driver and register it into the driver manager. A connection to the database is obtained from the Drive Manager by providing a database URL and other desired parameters. Close the connection after completion.
Connecting pools are an existing collection of database connections compared to such a way of this one, and these database connections can be reclaimed in multiple active J2EE applications. The connection in the connection pool is open and can be used to access. After the application uses a connection, this connection is not destroyed, but is returned to the connection pool, which can then be used for other applications. The connection pool increases the performance of database access, especially during the peak of the load. Pool is a collection of connecting pools. The main purpose of the multi-pool is to increase availability and implement load balancing between a set of connectors.
Why use the data source? A data source is a Java Naming and Directory Interface (JNDI) object that provides connection pool or multi-pool access. Connecting pools or multi-pools are required for configuring data sources. You can configure the data source using transaction properties. Non-transactional data sources are used in local transactions; while transactional data sources are used to distributed transactions. The data source encapsulates access to the database, hides the details involved in the accessory or multi-pool. In addition, the data source makes it easy to configure the transactional characteristics of the database connection. JDBC Data Source Factory is a JNDI object that uses it to get a connection from the connection pool within the application range.
The JDBC driver settings to establish a connection between WebLogic Server and DBMS is divided into two types: Type 2 and Type 4. The Type 2 JDBC driver requires a local library. When using the Type 2 JDBC driver, you need to put the path to the WebLogic shared library (or dynamic link library) directory
Configuring a JDBC connection pool now, we will consider how to create a connection pool and configure a variety of parameters related to it. To create a JDBC connection pool, right-click the JDBC> Connection Pools node in Administration Console, then select Configure a New JDBC Connection Pool. This will display a Configure a JDBC Connection Pool screen. Select Database Type - Oracle for the Oracle Database. Select a Database Driver and click the Continue button (see Figure 1).
figure 1
The Define Connection Properties screen is then displayed. In this picture, specify a Database Name, a Database User Name and a Password. Click the Continue button. The Test Database Connection is then displayed. In this picture, specify the value of the Driver ClassName, URL, and Properties fields. Driver classname is a driver class name for obtaining a database connection. The URL is a database URL for obtaining a connection. Properties is a list of properties used to create a connection. Table 1 specifies the DRIVER CLASSNAME and URL settings for different Oracle JDBC drivers.
Table 1 Driver class name and URL setting
In the URL setting,
Initial Capacity: The number of database connections created when creating a connection pool. Maximum Capacity: The maximum number of connections in the pool. Capacity Increment: The connection pool capacity is increment within the maximum capacity limit. Logindelay: The number of seconds to be delayed before creating each physical database connection. Allow Shrinking: When you set this item to True, if additional connections are not used, the connection pool is allowed to reduce the capacity to InitialCapacity. SHRINK FREQUENCY: The number of seconds to wait before the connection pool capacity is reduced. If you set Shrink Frequency to True, you must also set up shrinking to TRUE. TEST FREQUENCY: The number of seconds between database connection tests. After each Refresh Period time interval, if TestTableName is set, you will use TestTableName to test unused database connections. Test Reserved Connections: If this option is selected, the server tests before the connection is provided to the client. Test Created Connections: If you select this option, you will test the JDBC connection after you create a JDBC connection and you add a list of available connection lists in the JDBC connection pool. Test Released Connections: If you select this option, the server tests before returning the connection to the connection pool. Test Table Name: Database table name for JDBC connection tests. If TEST FREQUENCY is specified, Test Reserved Connections, Test Created Connections, or Test Released Connections is selected, Table Name is required. After configuring the CONNECTIONS screen, select the Apply button.
Configuring a JDBC multi-pool a multi-pool is a collection of connecting pools. Configure the connection pool for a multi-pool before creating a multi-pool. To create and configure a new multi-pool, right-click the JDBC> Multi Pools node in Administration Console and select Configure a New Multi Pool. The Configuration screen is then displayed. In the Multi Pool Configuration screen, specify the Algorithm Type and select the CREATE button. If AlgorithM Type is set to "High Availability", all available connections in a pool should have been used before using the connection in another pool. If Algorithm Type is set to "Load Balancing", the multi-pool will distribute the connection request to all the connecting pools in the multi-pool (see Figure 2).
figure 2
Select the Pools tab and select the connection pool to be added to the Pool in the Pools screen. Click the Apply button. The selected connection pool will be added to a plurality of pools. The connection pool used in the connection is based on Algorithm Type. Select the Target and Deploy tab and select a target server in the Target and Deploy screen. Click the Apply button. You can deploy a multi-pool on multiple servers. The JDBC> Multi Pools node in Administration Console will add a
Configuring a JDBC data source data source is a JNDI object for accessing the connection pool or multi-pool. Connecting pools or multi-pools are required for creating data sources. The connection pool is required for creating a transactional data source. Connection pools or multi-pools should be created before creating data sources. To create and configure a data source, right-click the JDBC> Data Source node in Administration Console and select Configure a New JDBCTXData Source. The Configuration screen is then displayed. Specify the settings of the field in the Data Source Configuration screen. JNDI Name is the JNDI path of the data source. Select Honor Global Transactions to create a transaction (TX) data source. If you don't have Honor Global Transactions, the created data source is the non-TX data source (see Figure 3). image 3
The Connect to Connection Pool screen is then displayed. In the Pool Name field, select a JDBC connection pool from the list of available connection pools, then click the Continue button. The data source is connected to the selected connection pool. The Target The Data Source screen will then be displayed. In this picture, select a target server and click the Continue button. This will deploy the data source on the selected server, but it can also be deployed on multiple servers. The JDBC> Data Sources nodes in Administration Console will add a
Comparison of Data Sources and TX Data Sources If Honor Global Transactions is selected in the data source configuration, the data source is TX data source. The data source is used with the connection pool or multi-pool. TX data sources are used with the connection pool. Data sources are used for local transactions. TX data source is used to distribute transactions. In the following cases, TX data source should be used instead of data sources:
A persistent entity bean hosted using a container. Access multiple resources during the transaction. Multiple database updates in a transaction. Use the same connection pool on multiple servers.
Configure the JDBC Data Source Plant JDBC Data Sourcework is a JNDI data source resource. Enterprise applications use the data source factory to get connected from the connection pool within the application range. To create and configure a JDBC data source factory, right-click the JDBC> Data Source Factories node in Administration Console, then select Configure A New JDBCDataSourceFactory. The Configuration screen is then displayed. In this picture, specify the value of the URL, Driver Class Name, Factory Name, and Properties fields, then click the Create button (see Figure 4).
Figure 4
The JDBC> Data Source Factories nodes in Administration Console will add a
In the JDBC connection pool configuration, set the value of INITIALCAPACITY to equal to MaxCapacity. If the value of INITIALCAPACITY is less than MaxCapacity, then the server creates an additional database connection when the load increases. In the case where the load is increased, resources must be allocated to create additional database connections, and the resources are also required for the completion of the JDBC client request. Set the value of MaxCapacity to equal to the number of concurrent client sessions that require JDBC connections: To determine the concurrent client session in a connection pool, select the connection pool node. Select the Monitoring tab. The value in the Active Connections column is the average number of concurrent client sessions. The value of Connections High is the maximum number of concurrent client sessions. After deploying an application and monitoring activity, you can modify the value of MaxCapacity. When the external client accesss the database with the JDBC via WebLogic Server, select Row Prefetch Enabled in the Data Source Configuration: By taking multiple rows in a server access, the prefetch can improve performance.
Conclusion According to the above outline process, WebLogic developers should configure Bea WebLogic 8.1 Server for Oracle 8.1 database. Configuring additional databases is similar to configuring Oracle 8.1. Add the ZIP / JAR file containing the driver class of the corresponding database to the ClassPath variable and specify the corresponding connection URL and the driver class name in the JDBC connection pool configuration.
Reference
Programming WebLogic JDBC: http://e-docs.bea.com/wls/docs81/jdbc/
About the author Ajay Vohra is a senior software engineer of Compuware. (More)
My personal supplement: