An article by IBM shows you have to implement a PreparedStatement interface that wraps around a real statement so that you can capture parameters for logging. However, when I tried the example code, it didn't compile under Java 5.0 (presumably because of the new features for PreparedStatement - though better query logging was mysteriously missing as a feature).
You may download my modifications to LoggableStatement below.
ExampleFrom IBM's article:
String sql = "select foo, bar from foobar where foo < ? " + "and bar = ?"; long fooValue = 99; String barValue = "christmas"; Connection conn = dataSource.getConnection(); PreparedStatement pstmt; if(logEnabled) // use a switch to toggle logging. pstmt = new LoggableStatement(conn,sql); else pstmt = conn.prepareStatement(sql); pstmt.setLong(1,fooValue); pstmt.setString(2,barValue); if(logEnabled) System.out.println("Executing query: "+ ((LoggableStatement)pstmt).getQueryString()); ResultSet rs = pstmt.executeQuery();