关于PreparedStatement 获得SQL语句的方法,没有直接的API可用,往往要自己实现或采用SQL profiler之类的工具,但在MySQL中有一个简便的方法:
if (statement instanceof com.mysql.jdbc.PreparedStatement) {
com.mysql.jdbc.PreparedStatement msqlPstmt = (com.mysql.jdbc.PreparedStatement)statement;
String sql = msqlPstmt.toString();
System.out.println(sql);
}