Is there any way I can get a JDBC log through the DriverManager??
I tried doing the DriverManager.setLogStream(). That does'nt give me enough
information about cursor open, fetch and close??
- vineet
Vineet Bhatia wrote:
That's all you're going to get. All the DriverManager does is to store the log stream.
It is the driver's responsibiliity to get the log stream and print out what it sees fit.
Some drivers are very chatty with the log, and others are more taciturn. Unless
there is a documented option for more/different debug output with this driver,
you will have to work with what you get now...
Joe Weinstein at B.E.A.
- vineet
"Joe Weinstein" <j...@bea.com> wrote in message
news:3C604453...@bea.com...
in your connection statement. This will help you a bit more in tracing SQL
statements.
log all the JDBC activity in the c:\temp\spy.log file
Best of Luck.
Sridhar Paladugu
Microsoft Developer Support
JDBC Webdata
This posting is provided "AS IS" with no warranties, and confers no rights.
Are you secure? For information about the Strategic Technology Protection
Program and to order
your FREE Security Tool Kit, please visit
<http://www.microsoft.com/security>.
Driver is com.microsoft.jdbc.sqlserver.SQLServerDriver
url:
jdbc:spy:{jdbc:microsoft:sqlserver://BLUE:1433;SELECTMETHOD=CURSOR;DATABASENAME=SERVER_3_2_6};
log=(file) h:\dev\od\java\lib\spy.log;linelimit=80
and result is :
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:477)
at java.sql.DriverManager.getConnection(DriverManager.java:137)
What did I do wrong ?
Thanks.
"Sridhar Paladugu[CompCon tech]" wrote:
I am sending you a sample code for logging using Spy Driver. But as far
support is considered microsoft does not provide support Spy Driver. I am
sending this sample code for review purpose only.
Code:
============================================================================
/*
This code is to test SQLServer Connectivity
*/
import java.sql.*;
import java.io.*;
import com.merant.jdbcspy.*;
public class Test{
private java.sql.Connection con = null;
//constructor
public Test(){}
private Connection getConnection() throws Exception{
con=null;
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Class.forName("com.merant.jdbcspy.SpyDriver");
java.io.OutputStream outFile = new
java.io.FileOutputStream("c:\\logs\\spy.log");
java.io.PrintStream outStream = new java.io.PrintStream (outFile,true);
DriverManager.setLogStream(outStream);
con =
DriverManager.getConnection("jdbc:spy:{jdbc:microsoft:sqlserver://localhost:
1433;DatabaseName=pubs;User=sridhar;Password=password};linelimit=80");
if(con!=null) System.out.println("Con complete");
}catch(SQLException e){
e.printStackTrace();
System.out.println("Error Trace in getConnection() : " +
e.getMessage());
}
return con;
}
public void displayDbProperties(){
DatabaseMetaData dm = null;
ResultSet rs = null;
try{
con= this.getConnection();
if(con!=null){
dm = con.getMetaData();
System.out.println("Driver Name: "+ dm.getDriverName());
System.out.println("Driver Version: "+ dm.getDriverVersion ());
System.out.println("Database Name: "+ dm.getDatabaseProductName());
System.out.println("Database Version: "+
dm.getDatabaseProductVersion());
rs = dm.getSchemas();
while(rs!=null&&rs.next()){
System.out.println("Schema: "+ rs.getString(1));
}
rs.close();
rs = null;
rs = dm.getCatalogs();
while(rs!=null&&rs.next()){
System.out.println("catalog: "+ rs.getString(1));
}
rs.close();
rs = null;
System.out.println("Catalog Seperator :"+ dm.getCatalogSeparator());
String[] tbl_types={"TABLE"};
rs = dm.getTables("pubs","%","%",tbl_types);
while(rs!=null&&rs.next()){
System.out.println("Table: "+ rs.getString(1)+ "." +
rs.getString(2)+"."+ rs.getString(3));
}
}else System.out.println("Error: No active Connection");
}catch(Exception e){
e.printStackTrace();
}
dm=null;
}
private void closeConection(Connection con){
try{
if(con!=null)
con.close();
con=null;
}catch(Exception e){
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception
{
Test myDbTest = new Test();
myDbTest.displayDbProperties();
}
}
Cheers!
"Sridhar Paladugu[CompCon tech]" wrote: