Application Server Solutions for Microsoft IIS and ASP.NET
       solutions   products   partners   company   support   downloads         store
JTurbo Self-Help: FAQ
Back to Search >  Back to Search Results

Faq ID 21
Product JTurbo, ServletExec
Category Debugging, JDBC
Question What can I do to help debug problems with my JDBC code?
Answer If your JDBC connections are created by using the DriverManger.getConnection() method then:
  • An application may enable the logging of debug messages to a PrintStream or PrintWriter for all loaded JDBC drivers (including JTurbo) by using the following code:
    PrintStream printStream = new PrintStream( ... );
    DriverManager.setLogStream( printStream );

    OR
    PrintStream printWriter = new PrintWriter( ... );
    DriverManager.setLogWriter( printWriter );

    For example, to have the debug messages logged to the console use:

    DriverManager.setLogStream( System.out );
    OR
    DriverManager.setLogStream( System.err );


    OR
    DriverManager.setLogWriter( new PrintWriter(System.out) );

    Note: the above information can also be found in Chapter 1 of the JTurbo 3.x and JTurbo 2005 User Guides

  • EXAMPLE:
    Here is the code for a JSP you could request to turn the debugging on or off:
    <%--
    Pass ?yes querystring when requesting this page
    in order to turn on debugging, otherwise debugging will be turned off
    --%>
    
    <%@ page import ="java.sql.*, java.io.*" %>
    
    <%
     String msg="JDBC debugging has been turned off.";
    
     if(request.getParameter("yes") != null)
     {
       DriverManager.setLogWriter(new PrintWriter(System.out));
       msg="JDBC debugging has been turned on.";
     }
     else
       DriverManager.setLogWriter(null);
    %>
    
    <%=msg%>
     

If your JDBC connections are created via a DataSource [ds] then:
  • PrintStream printWriter = new PrintWriter( ... );
    ds.setLogWriter( printWriter );


    For example, to have the debug messages logged to the console use:
    ds.setLogWriter( new PrintWriter( System.out ) );
    OR
    ds.setLogWriter( new PrintWriter( System.err ) );

    Note: the above information can also be found in the DataSource chapter (chapter 2) of the JTurbo 3.x and JTurbo 2005 User Guides

  • EXAMPLE:
    If using a datasource named "daffy" from within a Servlet/JSP engine where the datasource has been configured inside the engine, then here is the code for a JSP you could request to turn the debugging on or off:
    <%--
    Pass ?yes querystring when requesting this page
    in order to turn on debugging, otherwise debugging will be turned off
    --%>
    
    <%@ page import="javax.naming.*, javax.sql.DataSource, java.io.PrintWriter" %>
    
    <%
    
    Context ctx = new InitialContext(); 
    DataSource ds = (DataSource)ctx.lookup( "jdbc/daffy" );
    
    String msg="JDBC debugging has been turned off.";
    
    if(request.getParameter("yes") != null)
    {
     ds.setLogWriter( new PrintWriter( System.out ) ); //turn on JDBC debugging
     msg="JDBC debugging has been turned on.";
    }
    
    else
     ds.setLogWriter(null); //turn off JDBC debugging
    
    %>
    
    <%=msg%>
    



   
company media information terms of use privacy policy contact us