Results 1 to 2 of 2
Thread: Enabling JDBC logging (example)
-
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(); } } }
- 02-13-2008, 06:28 PM #2
Similar Threads
-
How to use JDBC Template classes to control basic JDBC processing and error handling
By Java Tip in forum Java TipReplies: 0Last Post: 04-01-2008, 10:17 AM -
what is logging
By Thirumalt in forum Java SoftwareReplies: 1Last Post: 11-26-2007, 11:37 AM -
Logging
By ravian in forum New To JavaReplies: 3Last Post: 11-18-2007, 10:22 PM -
How to use JDBC Template classes to control basic JDBC processing and error handling
By JavaBean in forum Java TipReplies: 0Last Post: 09-28-2007, 12:56 PM -
Java Logging
By vaswin in forum Advanced JavaReplies: 0Last Post: 08-06-2007, 01:18 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks