3

假设我的查询是这样的,这里 conn 是连接对象:

String countrycode=91;//it is dynamic in my case
String query = "update tblemployeedata set countrycode='?';
PreparedStatement pstmtUpdate = conn.prepareStatement(query);
pstmtUpdate.setString(1,countrycode);

现在设置上面的国家代码后,我想看到我的实际查询形成

update tblemployeedata set countrycode='91';

pstmtUpdate.executeUpdate();
4

2 回答 2

0

You can use pstmtUpdate.toString() method to see the actual query that is made after setting the parameters in the prepared statement.

于 2012-12-07T07:34:22.553 回答
-2

您可以通过以下方式获取查询的值。

Class stmt1 = pstmtUpdate.getClass();
java.lang.reflect.Field mem = stmt1.getField("sql");
String value= (String)mem.get(pstmt);

希望对你有帮助

于 2012-12-07T09:37:17.947 回答