BEA Logo BEA WebLogic Server Release 5.0

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

Technical FAQ: General questions about jDriver JDBC drivers

FAQ Index

How can I tell if the database is unavailable?

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

A 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.

Top of the page

Errors running t3dbping

Q 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 multitierutils.t3dbping utility, I receive an ORA-12154 error message. What's going on?

A 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.

Top of the page

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

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

A 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.

WebLogic 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 into 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.

WebLogic also provides a Type 3 pure-Java JDBC driver, WebLogic JDBC. A pure-Java JDBC driver does all of its work exclusively in Java, without any use of native methods, which is how WebLogic JDBC works. WebLogic JDBC can be used within the WebLogic framework without accessing any vendor-specific database libraries.

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.

Top of the page

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

A 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

Top of the page

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

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

A 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 Driver to create a connection.

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

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

Top of the page

Why can't my class find the WebLogic driver?

Q 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.

A 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 jDriver for Oracle), you can check examples of how to do this in the document Using jDriver for Oracle. 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 developers guide for your WebLogic jDriver. 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.
Top of the page

Locating the shared library for HP-UX green threads

Q When I install the .sl for HP-UX 10.20 in ~java/lib/PA_RISC/green_threads/ the JDK doesn't seem to be able find it. I thought the JDK automatically appended the green_threads library.

A The JDK does not append the green-threads library to the SHLIB_PATH. When operating on HP-UX, the JDK will not find the shared library (.sl) unless the library is in the path defined by SHLIB_PATH. To check the current value of SHLIB_PATH, at the command line type:

 $ echo $SHLIB_PATH
Use the set or setenv command (depending on your shell) to append the WebLogic shared library to the path defined by the symbol SHLIB_PATH. To have the shared library be recognized in a location that is not part of your SHLIB_PATH, you will need to contact your system administrator.

Top of the page

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

Q 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:" The host machine is up and running at the IP address What's the problem?

A We do not recognize 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).

Top of the page

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

Q 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?

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

Top of the page

Can I interleave two statements on a single connection?

Q 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?

A 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.

Top of the page

Why do I get the error "No weblogicoci32 in shared path" using the jDriver for Oracle JDBC driver?

Q When I try to use the jDriver for Oracle JDBC driver to connect to my database, I get a "No weblogicoci32/weblogicoci32 in shared path" error. What am I doing wrong?

A In order to use the WebLogic JDBC type-2 drivers, you need to have the native class libraries installed on your client machine and located where your program can find them. When your Java program goes to connect to your database, it needs to be able to access these libraries. The Oracle version of these libraries is shipped with the WebLogic distribution. See the installation guides for more information on installing jDriver for Oracle.

Top of the page

Why am I getting an access violation in Netscape?

Q I'm using a native driver, the Netscape Enterprise server/2.0b4, and the JDK 1.0.2 compiler. When I try to execute a JDBC query, I get an HTTPD.EXE access violation. No error message is recorded in my Netscape Enterprise server log. I've verified that the connection to my Sybase DBMS is working with utils.dbping, as you instructed in the installation instructions. What's the problem?

A You cannot use the native ddrivers with the server-side Java in the Enterprise server because Netscape does not allow third-party Java with native methods. You can use WebLogic JDBC or one of the Type 4 JDBC drivers, since they are Java-only.


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