How to use the Teradata JDBC Driver with WebLogic 12c



Prerequisites

Prior to starting WebLogic, you must ensure that the CLASSPATH of the server refers to the jar files that make up the Teradata JDBC Driver.

Your classpath must include terajdbc4.jar. Beginning with Teradata JDBC Driver 16.20.00.11, tdgssconfig.jar is no longer used. With older versions of the Teradata JDBC Driver, your classpath must also include tdgssconfig.jar.



Start the Administrative Console

The recommended way to create a Data Source and Connection Pool within WebLogic is to use the graphical interface of the administrative server.

Start a browser and open up url - 'http://localhost:7001/console' to administer the server.

When the browser window is displayed for WebLogic Server Administration Console 12c, enter the Username and Password in the Welcome screen.


Note: If a different port number for the administrative server was used, replace 7001 with that port number instead.



Open JDBC Data Sources

In the left pane for Domain Structure, click to expand the "Services" node.

Click to expand the "JDBC" node in Services.

Click on "Data Sources" in JDBC.

In the right pane, the Data Sources pane is shown. Click "New" → "Generic Data Source".



Set Data Source Parameters

The following table lists the parameters that must be set for a Data Source.

Field

Value

Example

Name

The user-defined display name for this Data Source. tera4DataSource

JNDI Name

User-defined JNDI name of the Data Source. tera4DS

Database Type

The database type to be used.
Other

Database Driver

The database driver to use to create database connections. Other


Enter the appropriate parameters, as shown in the figure below. Click "Next".




The Database Driver will already be set to Other. Click "Next".




Set the Transaction Options

For the Transaction Options shown below, uncheck "Supports Global Transactions". Click "Next" when you are finished.

NOTE: In WebLogic 9.x and Weblogic 10.x, an option for transaction processing, e.g. Emulate Two-Phase Commit, can be set only if you selected Supports Global Transactions. For TXDataSource, both of the check boxes for "Supports Global Transactions" and "Emulate Two-Phase Commit" should be checked.



Set the Connection Properties

The following table lists the parameters to be set for Connection Properties which will be used to create the connection pool for this data source.

Please note that the username of "guest" and password of "please" are examples and should be replaced by the actual username/password combination for your Teradata Database system.

Field

Value

Example

Database User Name

The database username. guest

Password

The password of the database user.

This can be used to override the password value in Properties. It allows you to avoid storing cleartext passwords.

After this value is applied it will not be visible as cleartext in the panel.
please


Enter the appropriate parameters, as shown in the figure below. Click "Next" to continue.



Test the Database Connection and Connection Properties

The following table lists further parameters that must be set to complete the Connection Properties for this data source and to test the database connection.

Field

Value

Example

Driver Class Name

The name of the class that implements the java.sql.Driver interface.

This value will be used to define the driver class name for the connection pool for this data source.
com.teradata.jdbc.TeraDriver

URL

Defines the URL that will be passed to the driver. The example database hostname is "xpsys03". You should use the actual database hostname for your site.

This value will be used to define the URL for the connection pool for this data source.

Please note that any connection URL parameter such as "CHARSET" or "TMODE" must be set within this URL parameter. These CANNOT be set within the properties panel.
jdbc:teradata://xpsys03

Properties

The properties to pass to the JDBC driver when creating the database connection. user=guest

Test Table Name

The table name or SQL statement to use to test the database connection.

NOTE: This property is optional.
SQL select count(*) from TestTableName


Enter the appropriate parameters, as shown in the figure below. Click "Test Configuration" when you are finished. In the Messages window, you should receive "Connection test succeeded." if your connection was successful. Click "Next" to continue.



Assign the Data Source

Select the target to deploy the JDBC Data Source. AdminServer is used for this Data Source.



Click "Finish" to complete the Data Source creation.

The Data Source that you just created should now appear in the table for the Data Sources for this domain.



DataSource.getConnection() vs. DataSource.getConnection(username,password)

WebLogic requires a valid database username and password to be specified in the connection pool definition. The database username and password specified in the connection pool definition are the ones that are always used to connect to the database.

When the application calls DataSource.getConnection(), then the username and password specified in the connection pool definition are used to connect to the database.

When the application calls DataSource.getConnection(username,password), then the username and password arguments to getConnection are validated against the WebLogic server realm.

If there is no WebLogic user defined in the WebLogic server realm that corresponds to the username argument to getConnection, then WebLogic will throw the following SQLException:

    Message: "User: YourUserId, failed to be authenticated."
    SQLState: null
    Error code: 0

If the username and password arguments to getConnection are successfully validated against the WebLogic server realm, then the username and password specified in the connection pool definition are used to connect to the database.

Note: The username and password arguments to getConnection are totally separate from the username and password specified in the connection pool definition. The username and password arguments to getConnection are used by WebLogic only, and are validated against the WebLogic server realm. The username and password arguments to getConnection are NOT used for the database.

Note: This behavior of WebLogic differs from the JDBC API standard, and it differs from the behavior of other application servers.



Using the Data Source

The following code creates the initial context:

Context ctx = new InitialContext();

To perform a JNDI lookup to obtain the Data Source, the following code can be used:

DataSource ds = (DataSource) ctx.lookup(jndiName);

To obtain a connection from the Data Source, the following code can be used:

Connection con = ds.getConnection();

At this point, the connection obtained behaves the same way as one that was obtained from the Driver Manager.

Complete sample servlets are listed here.



Performance Parameters

The following performance parameters are visible after selecting Connection Pool under the "Configuration" tab / "Connection Pool" subtab - for a Data Source within the WebLogic Administrator Console. Their setting can impact the performance of your application.

Maximum Capacity - This value specifies the maximum number of connections that the pool can contain. If this value is set smaller than the number of connections normally in use, then application response time may be negatively impacted as the application must wait for connections to be returned to the pool before proceeding.



Advanced Options

Login Delay - this defaults to zero and should remain at that value. Inserting a value here could cause unnecessary delays.

Test Connections on Reserve - this determines whether connections are tested before being given to a client. Turning on this option will cause your application to run slightly slower, but it will take advantage of WebLogic's automatic testing of connections, so that your application won't need to handle the situation where the connection it gets is not working. Turning off this option will cause your application to run slightly faster, but it will not use WebLogic's automatic testing of connections, so that your application will need to handle the situation where the connection that is obtained from the pool may not work.

Test Table Name - a table the Data Source user has access to which contains a small number of rows. The SQL executed will be: select count(*) from TestTableName

Also note that there is a Monitoring Tab available that can help you track the performance of a data source.



Preparation of CMP Entity Beans for Deployment

To manage transactions correctly for contained-managed persistence (CMP) entity beans, the WebLogic EJB container requires a TXDataSource (not a plain data source) to be specified.

To configure a new TXDataSource using WebLogic server Admin Console, the "Supports Global Transactions" and "Emulate Two-Phase Commit" checkboxes must be checked.