Skip Headers
Oracle® Database JDBC Developer's Guide and Reference,
11g Release 1 (11.1)

Part Number B31224-01
Go to Documentation Home
Go to Book List
Book List
Go to Table of Contents
Go to Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Go to next page
View PDF

30 Diagnosability in JDBC

In Oracle Database 11g, the JDBC drivers have been enhanced by including new diagnosabilty features and improving existing diagnosabilty features. These features enable users to diagnose problems in the applications that use Oracle JDBC drivers and the problems in the drivers themselves. They also reduce the effort required to develop and maintain Java applications that access an Oracle Database instance using Oracle JDBC drivers.

Oracle JDBC drivers provide the following diagnosabilty features that enable users to identify and fix problems in their JDBC applications:


The diagnosability features of the JDBC drivers are based on the standard java.util.logging framework and the MBean framework. Information about these standard frameworks is not covered in this document. Readers are advised to refer to the Sun Microsystems Web site to obtain information about these standard frameworks. Also refer to the JavaDoc for java.util.logging for information about the various configuration options available.


This feature logs information about events that occur when JDBC driver code runs. Events can include user-visible events, such as SQLExceptions, running of SQL statements, and detailed JDBC internal events, such as entry to and exit from internal JDBC methods. User can enable this feature to log specific events or all the events.

Prior to Oracle Database 11g, JDBC drivers supported J2SE 2.0 and 3.0. These versions of J2SE did not include java.util.logging. Therefore, the logging feature provided by JDBC driver releases prior to Oracle Database 11g, differs from the java.util.logging framework.

In Oracle Database 11g, the JDBC drivers no longer support J2SE 2.0 and 3.0. Therefore, the logging feature of JDBC drivers makes full use of the standard java.util.logging package. The enhanced logging system makes effective use of log levels to enable users to restrict log output to things of interest. It logs specific classes of information more consistently, making it easier for the user to understand the log file.

This feature does not introduce new APIs or configuration files. Only new parameters are added to the existing standard java.util.logging configuration file. These parameters are identical in use to the existing parameters and are intrinsic to using java.util.logging.


Oracle does not guarantee the exact content of the generated logs. To a large extent the log content is dependent on the details of the implementation. The details of the implementation change with every release, and therefore, the exact content of the logs are likely to change from release to release.

Enabling and Using JDBC Logging

Before you can start debugging your Java application, you need to enable and configure JDBC logging. This section covers the steps you need to perform to enable and use JDBC logging. It describes the following:

Configuring the CLASSPATH Environment Variable

Oracle ships several JAR files for each version of the JDBC drivers. The optimized JAR files do not contain any logging code and, therefore, do not generate any log output when used. To get log output, you must use the debug JAR files, which are indicated with a "_g" in the file name, like ojdbc5_g.jar or ojdbc6_g.jar. The debug JAR file must be included in the CLASSPATH environment variable.


Ensure that the debug JAR file, say ojdbc5_g.jar or ojdbc6_g.jar, is the only Oracle JDBC JAR file in the CLASSPATH environment variable.

Enabling Logging

You can enable logging in the following ways:

  • Setting a Java system property

    You can enable logging by setting the oracle.jdbc.Trace system property.

    java -Doracle.jdbc.Trace=true ...

    Setting the system property enables global logging, which means that logging is enabled for the entire application. You can use global logging if you want to debug the entire application, or if you cannot or do not want to change the source code of the application.

  • Programmatically

    You can programmatically enable or disable logging in the following way:

    First, get the ObjectName of the Diagnosability MBean. The ObjectName is,name=<loader>

    where, loader is a filtered version of the result of calling toString on the context ClassLoader.

    Now, write the following lines of code:

    // compute the ObjectName
    String loader = Thread.currentThread().getContextClassLoader().toString().replaceAll("[,=:\"]+", ""); name = new",name="+loader);
    // get the MBean server mbs =;
    // find out if logging is enabled or not
    System.out.println("LoggingEnabled = " + mbs.getAttribute(name, "LoggingEnabled"));
    // enable logging
    mbs.setAttribute(name, new"LoggingEnabled", true));
    // disable logging
    mbs.setAttribute(name, new"LoggingEnabled", false));

    Programmatic enabling and disabling of logging helps you to control what parts of your application need to generate log output.


Enabling logging using either of the methods would only generate a minimal log of serious errors. Usually this is not of much use. To generate and more useful and detail log, you must configure java.util.logging.

Configuring Logging

To generate a useful and detailed log, you must configure java.util.logging. This can be done either through a configuration file or programmatically.

A sample configuration file,, is provided as part of the JDBC installation in the demo directory. It contains basic information about how to configure java.util.logging and provides some initial settings that you can start with. You may use this sample file as is, edit the file and use it, rename the file and edit it, or create an entirely new file of any name.

To use a configuration file, you must identify it to the Java run-time. This can be done by setting a system property. For example:

java -Djava.util.logging.config.file=/jdbc/demo/

It is read by the java.util.logging system. This file can reside anywhere.

You can use both java.util.logging.config.file and oracle.jdbc.Trace at the same time.

java -Djava.util.logging.config.file=/jdbc/demo/ -Doracle.jdbc.Trace=true

You can use the default file. It may or may not get you the desired output. You can also create and use your own configuration file by following these steps:

  1. Create a file named You can use any name that you wish to.

  2. Insert the following lines of text in the file:

  3. Save the file.

  4. Set the system property to use this configuration file.

    java -Djava.util.logging.config.file=<filepath>/ ...

    where filepath is the path of the folder where you have saved the file.

You can also configure java.util.logging to dump the log output into a file. To do so, modify the configuration file as follows:


This will generate exactly the same log output and save it in a file named jdbc.log in the current directory.

You can control the amount of detail by changing the level settings. The defined levels from the least detailed to the most detailed are:

  • OFF

    Turns off logging.


    Logs SQLExceptions and internal errors.


    Logs SQLWarnings and bad but not fatal internal conditions.

  • INFO

    Logs infrequent but significant events and errors. It produces a relatively low volume of log messages.


    Logs SQL strings that are executed.

  • FINE

    Logs the entry and exit to every public method providing a detailed trace of JDBC operations. It produces a fairly high volume of log messages.


    Logs calls to internal methods.


    Logs calls to high volume internal methods.

  • ALL

    Logs all the details. This is the most detailed level of logging.


Levels more detailed than FINE generate huge log volumes.

In the example provided earlier, to reduce the amount of detail, change the java.util.logging.FileHandler.level setting from ALL to INFO:


Although you can, it is not necessary to change the level of the oracle.jdbc logger. Setting the FileHandler level will control what log messages are dumped into the log file.

Using Loggers

Setting the level reduces all the logging output from JDBC. However, sometimes you need a lot of output from one part of the code and very little from other parts. To do that you must understand more about loggers.

Loggers exist in a tree structure defined by their names. The root logger is named "", the empty string. If you look at the first line of the configuration file you see .level=SEVERE. This is setting the level of the root logger. The next line is oracle.jdbc.level=INFO. This sets the level of the logger named oracle.jdbc. The oracle.jdbc logger is a member of the logger tree. Its parent is named oracle. The parent of the oracle logger is the root logger (the empty string).

Logging messages are sent to a particular logger, for example, oracle.jdbc. If the message passes the level check at that level, then the message is passed to the handler at that level, if any, and to the parent logger. So a log message sent to oracle.log is compared against that logger's level, INFO if you are following along. If the level is the same or less (less detailed) then it is sent to the FileHandler and to the parent logger, 'oracle'. Again it is checked against the level. If as in this case, the level is not set then it uses the parent level, SEVERE. If the message level is the same or less it is passed to the handler, which there isn't one, and sent to the parent. In this case the parent in the root logger.All this tree stuff didn't help you reduce the amount of output. What will help is that the JDBC drivers use several subloggers. If you restrict the log messages to one of the subloggers you will get substantially less output. The loggers used by Oracle JDBC drivers include:

  • oracle.jdbc

  • oracle.jdbc.driver

  • oracle.jdbc.pool

  • oracle.jdbc.rowset

  • oracle.jdbc.xa

  • oracle.sql


The loggers used by the drivers may vary from release to release.

An Example

Suppose you want to trace what is happening in the oracle.sql component and also want to capture some basic information about the rest of the driver. This is a more complex use of logging. The following are the entries in the config file:

     # set levels 
     # configure handlers 

Let us consider what each line in the configuration file is doing.


Sets the logging level of the root logger to SEVERE. We do not want to see any logging from other, non-Oracle components unless something fails badly. Therefore, we set the default level for all loggers to SEVERE. Each logger inherits its level from its parent unless set explicitly. By setting the level of the root logger to SEVERE we ensure that all other loggers inherit that level except for the ones we set otherwise.


We want log output from both the oracle.sql and oracle.jdbc.driver loggers. Their common ancestor is oracle. Therefore, we set the level of the oracle logger to INFO. We will control the detail more explicitly at lower levels.


We only want to see the SQL execution from oracle.jdbc.driver. Therefore, we set the level to INFO. This is a fairly low volume level, but will help us to keep track of what our test is doing.


We are using a DataSource in our test and do not want to see all of that logging. Therefore, we turn it OFF.


We do not want to see the logging from the oracle.jdbc.util package. If we were using XA or rowsets we would turn them off as well.


We want to see what is happening in oracle.sql. Therefore, we set the level to INFO. This provides a lot of information about the public method calls without overwhelming detail.


We are going to dump everything to stderr. When we run the test we will redirect stderr to a file.


We want to dump everything to the console which is System.err. In this case, we are doing the filtering with the loggers rather than the handler.


We will use a simple, more or less human readable format.

When you run your test with this configuration file, you will get moderately detailed information from the oracle.sql package, a little bit of information from the core driver code, and nothing from any other code.

You can also use XMLFormatter. XMLFormatter is the best choice for logs that you send to Oracle Support, because it enables us to more easily use automated processing of the log output.

Performance, Scalability, and Security Issues

Although the logging feature enables you to trace or debug your application and generate detail log output, it has certain performance, scalability, and security issues.

Performance and Scalability Issues

Logging has substantial impact on performance. However, JDBC logging is generally not enabled in production systems. When logging is disabled, it will have no impact on performance.

It also has a negative impact on scalability. Logging involves protected access to a number of shared resources resulting in severely reduced scalability. This is intrinsic to the java.util.logging framework. However, in a typical production system, JDBC logging is not enabled and, therefore, will not have an impact on scalability.

Security Concerns

When full logging is enabled, it is almost guaranteed that all sensitive information will be exposed in the log files. This is intrinsic to the logging feature. However, only certain JDBC JAR files include the JDBC logging feature. The following JAR files include full logging and should not be used in a sensitive environment:

  • ojdbc5_g.jar

  • ojdbc5dms_g.jar

  • ojdbc6_g.jar

  • ojdbc6dms_g.jar

The following JAR files include a limited logging capability:

  • ojdbc5dms.jar

  • ojdbc6dms.jar


Database user names and passwords do not appear in log files created by these JAR files. However, sensitive user data that is part of a SQL statement, a defined value, or a bind value can appear in a log created using one of these JAR files.

Diagnosability Management

The JDBC diagnosability management feature introduces an MBean, oracle.jdbc.driver.OracleDiagnosabilityMBean. This MBean provides means to enable and disable JDBC logging.

See Also:

Refer to the JDBC JavaDoc for information about the OracleDiagnosabilityMBean API.

In future releases, the MBean will be enhanced to provide additional statistics about JDBC internals.

Security Concerns

This feature can enable JDBC logging. Enabling JDBC logging does not require any special permission. However, once logging is enabled, generating any log output requires the standard Java permission LoggingPermission. Without this permission, any JDBC operation that would generate log output will throw a security exception. This is a standard Java mechanism.