简体   繁体   English

如何获得将在DB2中执行PreparedStatement的完整查询?

[英]How to get the full query that a PreparedStatement is about to execute in DB2?

I'm working on a dynamic web project and using the PreparedStatement to execute the SQL queries against the DB2 database. 我正在研究一个动态Web项目,并使用PreparedStatement对DB2数据库执行SQL查询。

String myQuery = "select id from user where name = ?";
PreparedStatement stmt  = connection.prepareStatement(myQuery);
stmt.setString(1, test);
ResultSet resultSet  = statement.executeQuery();

How can I receive the full SQL query that is about to be executed on the DB2 server in the console? 如何接收将在控制台中的DB2服务器上执行的完整SQL查询?

If you are familiar with Debugging options in Eclipse. 如果您熟悉Eclipse中的Debugging选项。 You may try the following: 您可以尝试以下方法:

  1. Set a Breakpoint at ResultSet resultSet = statement.executeQuery(); ResultSet resultSet = statement.executeQuery();处设置断点ResultSet resultSet = statement.executeQuery();

  2. Right click your application, say Debug As select Java Application (or Whatever applicable in your case ie may be SpringBoot App etc. 右键单击您的应用程序,说“ Debug As选择Java Application (或适用于您情况的任何内容,例如SpringBoot App等)。

  3. Perform step that gets you to code mentioned in the Question. 执行将您带到问题中提到的代码的步骤。

  4. If you check Variables tab in Debug Perspective of Eclipse, you will find variables like myQuery , stmt (according to your code) 如果您在Eclipse的Debug Perspective中选中Variables tab ,则会发现myQuerystmt类的变量(根据您的代码)

  5. Whatever you see as value of stmt would be the full SQL query you need. 无论您认为stmt值是什么,都是您需要的完整SQL查询。

Also, if you don't want to keep looking at this variable always you may try Java Logging and Print your Full SQL query in Logs. 另外,如果您不想一直查看此变量,可以尝试使用Java Logging并在Logs中打印Full SQL查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM