Using JDBC Diagnostics

Purpose

This tutorial shows you how to use JDBC Diagnostics.

Time to Complete

Approximately 30 minutes

Topics

This tutorial covers the following topics:

 Prerequisites
 Using the OracleLogging Feature
 Invoking JavaNetTrace
 Summary

Viewing Screenshots

 Place the cursor over this icon to load and view all the screenshots for this tutorial. (Caution: This action loads all screenshots simultaneously, so response time may be slow depending on your Internet connection.)

Note: Alternatively, you can place the cursor over an individual icon in the following steps to load and view only the screenshot associated with that step. You can hide an individual screenshot by clicking it.

Prerequisites

Before you perform this tutorial, you should:

1.

Perform the Running Java in the Database

Back to Topic List

Using the OracleLogging Feature

You can use the OracleLogging feature to diagnose a problem. With the this feature, you can log information about events that occur when JDBC driver code runs. Events can include user-visible events, such as SQL exceptions, running of SQL statements, and detailed JDBC internal events, such as entry to and exit from internal JDBC methods. You can enable this feature to log specific events or all the events.

1.

Follow these steps to enable logging:

Use a text editor to open the OracleLog.properties file located in the wkdir directory.

Modify the package that you want to trace and select the level of tracing that you want

                               
oracle.jdbc.level = FINER
oracle.jdbc.driver.level = FINE
                            

 

2.

Uncomment the handlers statement. Note that this statement directs the output to a file.

                               
handlers = java.util.logging.FileHandler
                            

 

3.

Modify the logging type XML or Simple Text. In the example shown, we use the Simplet text format type.

                               
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
                            

If you prefer XML output, change the statement to:

java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter

Save the file and close it from the text editor.

 

4.

Use a text editor to open the oraclelog.xml file and observe the classpath setting.

You now have the ojdbc5_g.jar file (or any Jdbc jar file with _g in its name) in your classpath

Close the file.

 

5.

In a terminal window, change to your wkdir directory and then run the target program (any Jdbc program) as:

                               
cd wkdir
ant -f oraclelog.xml run.oraclelog
                            

Internally, this invokes:

                               
java -Doracle.jdbc.Trace=true 
          -Djava.util.logging.config.file=OracleLog.properties
-classpath ${ORACLE_HOME}/jdbc/lib/ojdbc5_g.jar:. BatchUpdates
                            

 

6.

The output is redirected to the file that was mentioned in step 2. This file is called jdbc.log.

Open the jdbc.log file and observe the logging information.

Note that every public operation is traced. For example, the setint and setstring methods are used to bind integer and strings to the prepared statement.

Close the text editor.

 

Back to Topic List

Invoking JavaNetTrace

You can enable JavaNetTrace to trace java code without changing the drivers. Using JavaNetTrace is equivalent to
Client-side tracing and processed similarly.

1.

Use a text editor to open the jnettrace.xml file located in the wkdir directory.

Note that the serverport is set to 1521.

Close the file.

 

2.

Open a terminal window. Change to the wkdir directory. Run the JavaNnet utility to see JavaNetTrace in action .

                               
                                 
cd wkdir
                              
                            
                               
                                 
ant -f jnettrace.xml run.jnettrace
                              
                            

Note that session is waiting for connection.

 

3.

Open a second terminal window.

Change to the wkdir directory.

cd wkdir

Run the sample demonstration program that connects through the jnet port by executing the following command:

ant -f jnettrace.xml run.sample

This generates a trace file.

 

3.

Java net trace is equivalent to Client-side tracing and processed similarly. This creates a client_<hex number>.trc file in the local directory where the client side sqlnet trace resides. This is non-intrusive and hence JNetTrace can be run on any machine and need not be on the database server. The trace can be run on any version of client/server.

To view the latest file generated, execute the following statement:

ls -lt|head

Notice the client_xxx.trc file.

 

4.

Use a text editor to open the client_xxx.trc file and examine the contents.

It is similar to a client side SQLnet trace file.

Exit the editor.

 

5.

C lose your terminal windows.

 

Back to Topic List

Summary

In this tutorial, you learned about the following:

 Use OracleLogging Features
 Use JavaNet Tracing

Back to Topic List

 Place the cursor over this icon to hide all screenshots.

 

 

 

Left Curve
Popular Downloads
Right Curve
Untitled Document