Debugging PreparedStatement

1) Using a Debug package that developed by java underground:

Connection con = DriverManager.getConnection(url);
DebugLevel debug = DebugLevel.ON;
String sql = "SELECT name,rate FROM EmployeeTable WHERE rate > ?";
//Use a factory instead of Connection to get a PreparedStatement.
//PreparedStatement ps = con.prepareStatement(sql);
  PreparedStatement ps = StatementFactory.getStatement(con,sql,debug);
  ps.setInt(1,25);
//If ps is a DebuggableStatement, you see the statement,
//otherwise, an object identifier is displayed
  System.out.println(" debuggable statement= " + ps.toString());


Reference: http://www.javaworld.com/javaworld/jw-01-2002/jw-0125-overpower.html?page=3

Download the source code: http://www.javaworld.com/javaworld/jw-01-2002/overpower/jw-0125-debug.zip

2) Using LOG4J:

log4j.rootLogger=DEBUG, stdout 
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%c{1} - %m%n
log4j.logger.java.sql.Connection=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG

留言

這個網誌中的熱門文章

Disable ionic's sidemenu content drag to toggle menu

java.lang.NoClassDefFoundError: org/apache/xerces/jaxp/datatype/XMLGregorianCalendarImpl$Parser

Multiple writable mappings exist for the field. Only one may be defined as writable, all others must be specified read-only.