关于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);
}
本文介绍了一种在MySQL中获取PreparedStatement所执行SQL语句的方法。通过将Statement实例向下转型为MySQL特定的PreparedStatement,可以方便地获取到SQL语句并打印出来。
3658

被折叠的 条评论
为什么被折叠?



