To assist you in monitoring the performance of your applications with the IBM® Data Server Driver for JDBC and SQLJ, the driver provides two methods to collect information for a connection.
That information is:
The server time that is returned by DB2SystemMonitor.getServerTimeMicros does not include commit or rollback time.
import java.sql.*;
import com.ibm.db2.jcc.*;
public class TestSystemMonitor
{
public static void main(String[] args)
{
String url = "jdbc:db2://sysmvs1.svl.ibm.com:5021/san_jose";
String user="db2adm";
String password="db2adm";
try
{
// Load the IBM Data Server Driver for JDBC and SQLJ
Class.forName("com.ibm.db2.jcc.DB2Driver");
System.out.println("**** Loaded the JDBC driver");
// Create the connection using the IBM Data Server Driver for JDBC and SQLJ
Connection conn = DriverManager.getConnection (url,user,password);
// Commit changes manually
conn.setAutoCommit(false);
System.out.println("**** Created a JDBC connection to the data source");
DB2SystemMonitor systemMonitor = 1
((DB2Connection)conn).getDB2SystemMonitor();
systemMonitor.enable(true); 2
systemMonitor.start(DB2SystemMonitor.RESET_TIMES); 3
Statement stmt = conn.createStatement();
int numUpd = stmt.executeUpdate(
"UPDATE EMPLOYEE SET PHONENO='4657' WHERE EMPNO='000010'");
systemMonitor.stop(); 4
System.out.println("Server elapsed time (microseconds)="
+ systemMonitor.getServerTimeMicros()); 5
System.out.println("Network I/O elapsed time (microseconds)="
+ systemMonitor.getNetworkIOTimeMicros());
System.out.println("Core driver elapsed time (microseconds)="
+ systemMonitor.getCoreDriverTimeMicros());
System.out.println("Application elapsed time (milliseconds)="
+ systemMonitor.getApplicationTimeMillis());
conn.rollback();
stmt.close();
conn.close();
}
// Handle errors
catch(ClassNotFoundException e)
{
System.err.println("Unable to load the driver, " + e);
}
catch(SQLException e)
{
System.out.println("SQLException: " + e);
e.printStackTrace();
}
}
}
String url = "jdbc:db2://sysmvs1.stl.ibm.com:5021/san_jose" +
":traceFile=/u/db2p/jcctrace;" +
"traceLevel=" + com.ibm.db2.jcc.DB2BaseDataSource.TRACE_SYSTEM_MONITOR + ";";
The
trace records with system monitor information look similar to this: [jcc][SystemMonitor:start]
…
[jcc][SystemMonitor:stop] core: 565.67ms | network: 211.695ms | server: 207.771ms