Consultor Eletrônico



Kbase P122044: SQL: How to Enable the DataDirect JDBC Spy using Java?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   02/01/2009
Status: Verified

GOAL:

SQL: How to Enable the DataDirect JDBC Spy using Java?

GOAL:

How to Specify the SpyAttributes connection property for connections using the JDBC Driver Manager?

GOAL:

Sample java code to enable the DataDirect JDBC Spy

GOAL:

Sample log file output by the DataDirect JDBC Spy

FACT(s) (Environment):

All Supported Operating Systems

FIX:

The following java code demonstrates how to enable the DataDirect JDBC Spy in a JAVA program:
import com.progress.sql.sp.*;
import java.sql.*;
import java.util.*;

public class SelectCustomers{
public static void main(String [] args) {
String url = "jdbc:datadirect:openedge://localhost:23456;databaseName=sports2000;SpyAttributes=(log=(file)spy.log;logTName=yes;timestamp=yes)";
String drv = "com.ddtek.jdbc.openedge.OpenEdgeDriver";
String usr = "yshanshi";
String pwd = "progress";
String sql = "SELECT custnum,name FROM PUB.Customer";
Connection con;
Statement stmt;
ResultSet rs;
try {
Class.forName(drv);
}
catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
java.io.PrintStream pStream = new java.io.PrintStream(System.out, true);
con = DriverManager.getConnection(url, usr, pwd);
con.setAutoCommit(false);
stmt = con.createStatement();
rs = stmt.executeQuery(sql);
rs.next();
System.out.println(rs.getString("custnum") + " -> " + rs.getString("name"));
stmt.close();
}
catch (SQLException ex) {
System.out.println ("*** (debugging) in sql exception block...");
while (ex != null) {
System.out.println ("SQLState: " + ex.getSQLState ());
System.out.println ("Message: " + ex.getMessage ());
System.out.println ("VendorCode: " + ex.getErrorCode());
ex = ex.getNextException ();
System.out.println ("");
}
}
catch (java.lang.Exception ex) {
System.out.println ("*** (debugging) in general exception block...").;
// Got some other type of exception. Dump it.
ex.printStackTrace ();
}
finally {
System.out.println ("finally...");
}
}
}

The following file spy.log is generated by the execution of the above JAVA program:
spy(main)(2007/02/05 16:51:58.568)>> Connection[1].setAutoCommit(boolean autoCommit)
spy(main)(2007/02/05 16:51:58.578)>> autoCommit = false
spy(main)(2007/02/05 16:51:58.598)>> OK
spy(main)(2007/02/05 16:51:58.598)>> Connection[1].createStatement()
spy(main)(2007/02/05 16:51:58.618)>> OK (Statement[1])
spy(main)(2007/02/05 16:51:58.618)>> Statement[1].executeQuery(String sql)
spy(main)(2007/02/05 16:51:58.618)>> sql = SELECT custnum,name FROM PUB.Customer
spy(main)(2007/02/05 16:51:58.698)>> OK (ResultSet[1])
spy(main)(2007/02/05 16:51:58.698)>> ResultSet[1].next()
spy(main)(2007/02/05 16:51:58.698)>> OK (true)
spy(main)(2007/02/05 16:51:58.698)>> ResultSet[1].getString(String columnName)
spy(main)(2007/02/05 16:51:58.698)>> columnName = custnum
spy(main)(2007/02/05 16:51:59.738)>> OK (1)
spy(main)(2007/02/05 16:51:59.738)>> ResultSet[1].getString(String columnName)
spy(main)(2007/02/05 16:51:59.738)>> columnName = name
spy(main)(2007/02/05 16:51:59.738)>> OK (Lift Tours)
spy(main)(2007/02/05 16:51:59.748)>> Statement[1].close()
spy(main)(2007/02/05 16:51:59.748)>> OK .