Results 1 to 2 of 2
  1. #1
    Java Tip's Avatar
    Java Tip is offline Moderator
    Join Date
    Nov 2007
    Posts
    1,694
    Blog Entries
    430
    Rep Power
    10

    Default Enabling JDBC logging (example)

    The example presented below shows how to enable JDBC logging.

    Java Code:
    class JDBCapp  {
      static MyConnection theConn;
    
      public static void main (String args[]) {
        new JDBCapp().doit();
        }
    
      public void doit() {
        theConn = new MyConnection();
        theConn.connect("EAS Demo DB V3", "dba", "sql");
    
    PreparedStatement prepstmt;
    try {
      prepstmt = theConn.dbConn.prepareStatement
       ("SELECT emp_id FROM employee" );
      prepstmt.execute();
      prepstmt.close();
      }
    catch (Exception e) { e.printStackTrace(); }
      theConn.disconnect();
      }
    }
    
    
    class MyConnection {
      Connection dbConn = null;
      void connect(String db, String user, String passw) {
        try {
          Driver d = 
           (Driver)Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
          String URL = "jdbc:odbc:" + db;
          dbConn = DriverManager.getConnection(URL, user, passw);
          java.io.PrintWriter w =
            new java.io.PrintWriter
               (new java.io.OutputStreamWriter(System.out));
          DriverManager.setLogWriter(w);
          }
        catch (Exception e) {
          e.printStackTrace();
          }
        }
    
      void disconnect() {
        try {
          dbConn.close();
          }
        catch (Exception e) {
          e.printStackTrace();
          }
        }
    }

  2. #2
    itgalary's Avatar
    itgalary is offline Member
    Join Date
    Feb 2008
    Posts
    6
    Rep Power
    0

Similar Threads

  1. Replies: 0
    Last Post: 04-01-2008, 11:17 AM
  2. what is logging
    By Thirumalt in forum Java Software
    Replies: 1
    Last Post: 11-26-2007, 12:37 PM
  3. Logging
    By ravian in forum New To Java
    Replies: 3
    Last Post: 11-18-2007, 11:22 PM
  4. Replies: 0
    Last Post: 09-28-2007, 01:56 PM
  5. Java Logging
    By vaswin in forum Advanced Java
    Replies: 0
    Last Post: 08-06-2007, 02:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •