BEA Logo BEA WebLogic Server Release 6.1

  Corporate Info  |  News  |  Solutions  |  Products  |  Partners  |  Services  |  Events  |  Download  |  How To Buy

   Programming WebLogic JDBC:   Previous topic   |   Next topic   |   Contents   

 

Using Third-Party Drivers with WebLogic Server

 

This topic discusses these sections regarding third-party JDBC drivers:

Overview of Third-Party JDBC Drivers

WebLogic Server works with third-party JDBC drivers that offer the following functionality:

In addition, WebLogic Server multitier drivers only support the JDBC API and do not support additional functionality. For example, calls to proprietary Oracle methods are not currently supported, but are planned in a future release.

Using the Third-Party Drivers

This section describes how to set up and use the following third-party two-tier, Type 4 drivers with WebLogic Server:

These drivers are bundled with your WebLogic Server distribution; the weblogic.jar file contains the Oracle Thin Driver and Sybase jConnect classes. If you want to use the Oracle Thin Driver 817, it is available as a download from Oracle. Additional information about these Oracle and Sybase drivers is available at their respective Web sites.

Limitations

Please be aware of the following limitations:

Setting the Environment for Your Third-Party Driver

The following topics describe how to set your CLASSPATH for Windows NT and Unix for the Oracle Thin Driver and Sybase jConnect Driver.

CLASSPATH for Third-Party Driver on Windows NT

Set your CLASSPATH, pre-pending the weblogic.jar file, as follows:

set CLASSPATH=c:\bea\weblogic6.0\lib\weblogic.jar;%CLASSPATH%

Where c:\bea\weblogic6.0 is the directory where you installed WebLogic Server.

CLASSPATH for Third-Party Driver on Unix

Set your CLASSPATH, pre-pending the weblogic.jar file, as follows:

export CLASSPATH=/bea/weblogic6.0/lib/weblogic.jar;$CLASSPATH

Where /bea/weblogic6.0 is the directory where you installed WebLogic Server.

Getting a Connection with Your Third-Party Driver

The following topics describe two ways to get a connection using a third-party, Type 4 driver, such as the Oracle Thin Driver and Sybase jConnect Driver. BEA recommends you use connection pools, data sources, and JNDI Lookup to establish your connection. As an alternative, you can get a simple connection directly between the Java client and the database.

Using Connection Pools With a Third-Party Driver

First, you create the connection pool and data source using the Administration Console, then establish the connection using a JNDI Lookup.

Create the Connection Pool and DataSource

See Managing JDBC Connectivity in the Administration Guide for information on how to use the Administration Console to:

Using a JNDI Lookup to Obtain the Connection

To access the driver using JNDI, obtain a Context from the JNDI tree by providing the URL of your server, and then use that context object to perform a lookup using the DataSource Name.

For example, to access a DataSource called "myDataSource" that is defined in Administration Console:

Context ctx = null;
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,
"t3://hostname:port");

  try {
ctx = new InitialContext(ht);
javax.sql.DataSource ds
= (javax.sql.DataSource) ctx.lookup ("myDataSource");
java.sql.Connection conn = ds.getConnection();

   // You can now use the conn object to create 
// a Statement object to execute
// SQL statements and process result sets:

Statement stmt = conn.createStatement();
stmt.execute("select * from someTable");
ResultSet rs = stmt.getResultSet();

   // Do not forget to close the statement and connection objects
// when you are finished:

   stmt.close();
conn.close();
}
catch (NamingException e) {
// a failure occurred
}
finally {
try {ctx.close();}
catch (Exception e) {
// a failure occurred
}
}

(Where hostname is the name of the machine running your WebLogic Server and port is the port number where that machine is listening for connection requests.)

In this example a Hashtable object is used to pass the parameters required for the JNDI lookup. There are other ways to perform a JNDI look up. For more information, see Programming WebLogic JNDI .

Notice that the JNDI lookup is wrapped in a try/catch block in order to catch a failed look up and also that the context is closed in a finally block.

Setting a Direct Connection

This simple example shows you how to establish a connection directly between the java client and the database.

Create the Connection Pool

Using the Administration Console, do the following:

Setting a Direct Connection Using the Oracle Thin Driver

The following example shows how to set a direct connection using the Oracle Thin Driver.

In the code:

Setting a Direct Connection Using the Sybase jConnect Driver

The following example shows how to set a direct connection using the Sybase jConnect Driver.

In the code:

// Sybase jConnect
con = driver.connect
("jdbc:sybase:Tds:myDB@myhost:myport), props);

 

Back to Top