Setting the Log Stream

Setting the Log Stream

When debugging Java Database Connectivity (JDBC) problems, it can be difficult to locate the source of errors. However, one facility that can be used to accomplish this is the logging/tracing stream used by JDBC. Most JDBC drivers write information to the stream that can be helpful in debugging errors. You can take advantage of this fact by redirecting the output so that you’re able to review it. Simply call the static setLogStream() method in the java.sql.DriverManager class, specifying a instance representing the desired destination of the output. This code redirects the JDBC drivers’ diagnostic messages to the console:


If you wish to store the output in a file, simply create a PrintStream instance that represents a disk file:

 FileOutputStream fos = new FileOutputStream("jdbclog.txt");PrintStream ps = new PrintStream(fos);DriverManager.setLogStream(ps);


Share the Post: