Corporate Info | News | Solutions | Products | Partners | Services | Events | Download | How To Buy
Frequently Asked Questions: Previous topic | Next topic | Contents

WebLogic Frequently Asked Questions: WebLogic jDriver JDBC Drivers

- What do you mean by "two-tier" and "multitier" drivers?

- How can I tell if the database is unavailable?

- Errors running t3dbping

- What's a "native" JDBC driver? What's the difference between a Java and a "Java-only" JDBC driver?

- What do I need to connect to a database with JDBC and Java?

- How do I connect to a DBMS with a WebLogic jDriver JDBC driver?

- Why can't my class find the WebLogic driver?

- Unable to connect to my database! UnknownHost Exception . . .

- How can I find out how many rows are returned after I execute a query?

- Can I interleave two statements on a single connection?

- Why am I getting an UnsatisfiedLinkError?

What do you mean by "two-tier" and "multitier" drivers?

What do you mean by "two-tier" and "multitier" JDBC drivers?

Two-tier drivers - such as jDriver for Oracle - call the vendor libraries for each specific database. Because the vendor libraries are not written in Java, a two-tier driver uses "native methods." This requires the vendor's database libraries, (.dll or .so) to be installed on the computer running the Java code so that the JVM can call into the libraries.

With multitier (also called "three-tier") drivers, an intermediate application server sits between the JDBC driver and the database. WebLogic's multitier JDBC drivers, the JTS, Pool and RMI drivers, are pure-Java and do not use native methods; therefore, these drivers do not require client-side installation of vendor libraries.

A client application that uses any of these WebLogic multitier drivers connects to the intermediate application server - the WebLogic Server - and the application server connects to the database on behalf of the client. When you use the WebLogic multitier drivers, your clients do not need vendor libraries. Only one copy of the vendor library is required, along with a two-tier JDBC driver, on the computer running the WebLogic Server.

For additional information, see Choosing a JDBC driver.

How can I tell if the database is unavailable?

Is there a way to know whether a database has gone down, and come up again?

You can do this from within your program. A database that is down has no way of notifying anyone of its status (because it is down). Therefore, your program logic should test for the availability of a resource (such as a database) before accessing that resource, and then you can determine how your program should respond to that information. For examples, you could notify the user that there is a problem and exit gracefully. You might also wish to have your program notify the appropriate person that there is a problem with the database.) In the case of java.sql.Connection, an SQLException is thrown that you can catch and deal with as suggested above.

If you are using connection pools, you have additional options for dealing with this situation.

Generally, database availability is a system-administration problem that probably requires human intervention.

Errors running t3dbping

I am testing my Oracle database connections under UNIX. I am able to run SQL*PLUS and can successfully ping the database using utils.dbping. However, when I use the multitier utils.t3dbping utility, I receive an ORA-12154 error message. What's going on?

First, make sure that your ORACLE_HOME environment variable is correctly set to point to your Oracle installation. This variable must be set in the environment where the WebLogic server is running.

In the C-shell issue the following command:

      $ setenv ORACLE_HOME path

where path is the path to your Oracle installation.

In the Bourne shell, issue the following commands:

      $ ORACLE_HOME=path
      $ export ORACLE_HOME

where path is the path to your Oracle installation. When you ping your database using the two-tier utils.dbping utility, the JDBC driver loads the database client library and establishes the connection to the database. When you use the multitier utils.t3dbping utility, the WebLogic Server loads a two-tier driver and uses it to establish a database connection. In both cases, the same method is used to connect to the database. SQL*PLUS works because it doesn't require ORACLE_HOME to find the client libraries.

If you are still experiencing problems, try this:

1. Open a command shell.

2. Run the two-tier version of utils.dbping in this shell.

3. Start WebLogic in this shell from the command line:

       $ java -ms32m -mx32m weblogic.server

4. Open a second command shell.

5. Run the utils.t3dbping in the second shell against the server running in the first command shell.

If this procedure doesn't work, please send the output from these commands to WebLogic technical support.

What's a "native" JDBC driver? What's the difference between a Java and a "Java-only" JDBC driver?

Why are some JDBC drivers billed as "Java-only?" What's a "native" JDBC driver?

Some JDBC drivers written in Java work by calling database vendors' platform-specific database client libraries, such as Oracle's OCI or Sybase's DB-Library. These libraries are written in C, not Java. A JDBC driver that uses these native libraries uses a Java mechanism called Java Native Interface (JNI) that makes it possible for a Java program to access platform-specific native code. There are some restrictions on how and where native methods can be used. For example, Java JDBC drivers are not appropriate for use in Netscape applets because of restrictions on the use of native methods.

BEA offers a Type 2 "native" JDBC driver that works only with specific, individual client libraries, for the Oracle DBMS. Because the vendors' client libraries are not written in Java, the WebLogic native drivers use a very thin C layer to make calls to the client library. This WebLogic native layer is supplied as a .dll for Windows or an .so or .sl for UNIX. When you use a WebLogic native driver, you need the WebLogic Java classes as well as the appropriate native library for the vendor library for your database.

In addition, WebLogic supplies Type 4 pure-Java two-tier drivers for Informix and Microsoft SQL Server. These can be downloaded separately from the WebLogic website.

What do I need to connect to a database with JDBC and Java?

What do I need to connect to a database with JDBC and Java?

You need the following pieces:

- A database (Oracle or Microsoft SQL Server, for example)

- A JDBC driver, such as a WebLogic JDBC driver (jDriver for Oracle, or jDriver for Microsoft SQL Server)

- For a Type 2 JDBC driver, the 32-bit vendor client libraries for the database (.dll for Windows NT or .so or .sl for UNIX)

- If you want to access a database using JDBC from an applet running in a browser, the WebLogic multitier JDBC driver, WebLogic JDBC

- Java Developers Kit

How do I connect to a DBMS with a WebLogic jDriver JDBC driver?

Can you give me some tips on how to connect to a DBMS using a WebLogic jDriver JDBC driver?

You do this in a Java program by setting properties with a Properties object, and then passing the Properties object and the URL of the driver to the DriverManager to create a connection.

This is documented in detail for each of the WebLogic dJDBC drivers in the following Developers Guides:

- Overview of the native two-tier JDBC drivers

  - jDriver for Oracle

  - jDriver for Microsoft SQL Server

  - jDriver for Informix

- WebLogic JDBC developers guide.

If you use the utils.dbping utility to check your database connection, you get output that includes sample code for connecting to the database.

Why can't my class find the WebLogic driver?

I've written a test class to log into an Oracle database, insert and delete some records, and close. When I try to run my class file, it fails to find the WebLogic driver.

Here is a troubleshooting checklist:

- Did you use the product's application or the command-line dbping utility to test your connection to the database?

- Are your DBMS environment variables set in the shell from which you are running the application, or - if you are using an applet - the shell from which you are running the WebLogic Server?

- Did you install the appropriate 32-bit vendor library (required by a two-tier driver)?

- Are you loading the WebLogic driver properly in your code? If you are using a two-tier driver (like WebLogic jDriver for Oracle), you can check examples of how to do this in the Native driver overview and implementation guide. If you are using WebLogic JDBC, then you must load two JDBC drivers, one for the connection between the WebLogic Server and the database, and one for the connection between the WebLogic JDBC Client and the WebLogic Server. Please verify that you are doing this properly by checking Step 4 in the Developers Guide for WebLogic JDBC.

- Did you specify the datasource properly? Do this with a URL or with a java.util.Properties object. There is also information on this in the Native JDBC driver overview and implementation guide and the Developers Guide for WebLogic JDBC. For more detailed information on using URLs, check the administrator guide Using URLs with WebLogic products.

- If you are using WebLogic JDBC, WebLogic's multitier JDBC driver, you also need to specify a WebLogic Server with a URL. Check your syntax against the example code in the WebLogic JDBC developers guide.

Unable to connect to my database! UnknownHost Exception . . .

We think we're just one step away from testing our connectivity to our Oracle database. We have been able to test connectivity from other applications and through SQL*PLUS, but we're still unable to connect from our Java application with your JDBC driver. We're getting the error: "Failed to find host: java.net.UnknownHostException." The host machine is up and running at the IP address 127.0.0.1. What's the problem?

We do not recognize 127.0.0.1 as a valid IP address, since it is a special case that is the equivalent of "localhost". To use our products, you must have a permanent IP address assigned by your Internet Service Provider (ISP).

How can I find out how many rows are returned after I execute a query?

After I execute a query (using the Statement.execute() methods), how can I find out how many rows are returned in the ResultSet, if no rows are returned, and if any error occurred while executing the query?

You do not know how many rows are in a ResultSet until you have fetched them all, that is, until you have called the ResultSet.next() method for each record returned by the query. If an error occurs, an Exception will be thrown.

Can I interleave two statements on a single connection?

I want to interleave two statements over the same connection, executing first one, then the other. I'm executing a JDBC PreparedStatement repeatedly, and I want to avoid the overhead of opening and closing Statements repeatedly. How can I do this?

If you are using an Oracle database, you can interleave multiple Statements on the same Connection.

For Sybase and Microsoft SQL Server, the fundamental rule for multiple statement execution on the same Connection is this: After you execute a Statement, you must read all the results from that Statement, and then cancel or close the Statement. If you try to issue another execute on that Statement or on any other Statement on the same Connection, you will get a DB-Library error.

You can open another Connection to perform other operations on the database, but the SQL Server may cause your new Connection to wait if it accesses a table or a page that has been locked by a query on the first Connection. In some cases this will also lead to a deadlock on the SQL Server, which will eventually cause a SQLException to be returned to one of the Connections.

Why am I getting an UnsatisfiedLinkError?

I am working on Windows with a Type 2 WebLogic jDriver. My CLASSPATH setting is correct but I get an UnsatisfiedLinkError when I try to use the connection or when I test the connection using java utils.dbping as you suggest. Here is the stock trace:

java.sql.SQLException: System.loadLibrary threw java.lang.UnsatisfiedLinkError with the message "no weblogicoci34 in shared library path."

             at weblogic.jdbcbase.oci.Driver.connect(Driver.java:115)

             at java.sql.DriverManager.getConnection(Compiled Code)

             at utils.dbping.main(dbping.java:139)

Any Type 2 WebLogic jDriver requires that the native .dll be in your path. See the installation instructions for your Weblogic jDriver -- Installing WebLogic jDriver for Oracle, Installing WebLogic jDriver for Informix , or Installing WebLogic jDriver for Microsoft SQL Server.

Copyright © 2000 BEA Systems, Inc. All rights reserved. Required browser: Netscape 4.0 or higher, or Microsoft Internet Explorer 4.0 or higher.