Technical FAQ: General questions about jDriver JDBC driversFAQ Index
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.
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?
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.
If you are still experiencing problems, try this:
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.
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.
What do I need to connect to a database with JDBC and Java?
You need the following pieces:
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 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.
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:
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.
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_PATHUse 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.
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).
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.
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.
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?
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.
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?
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.