![]() |
![]() |
|
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.
Properties props = new Properties();
props.setProperty("user", "scott");
props.setProperty("password", "tiger");
Driver driver = null;
Connection con = null;
// ThinDriver driver
driver = (Driver)Class.forName
("oracle.jdbc.driver.OracleDriver").newInstance();
// Thin driver connection
con = driver.connect
("jdbc:oracle:thin:@myHost.mydomain.com:1521:DEMO", props);
Setting a Direct Connection Using the Sybase jConnect Driver
The following example shows how to set a direct connection using the Sybase jConnect Driver.
Properties props = new Properties();
props.setProperty("user", "myuser");
props.setProperty("password", "mypass");
Driver driver = null;
Connection con = null;
// Sybase jConnect driver
driver = (Driver)Class.forName
("com.sybase.jdbc.SybDriver").newInstance()
// Sybase jConnect
con = driver.connect
("jdbc:sybase:Tds:myDB@myhost:myport), props);
|
Copyright © 2000 BEA Systems, Inc. All rights reserved.
|