oracle 从 PreparedStatement 查询

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3860988/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 21:38:30  来源:igfitidea点击:

Query from PreparedStatement

javaoracleprepared-statement

提问by Harish

Is there any way to get the Oracle query from PreparedStatement .I know its not possible as such I can't use log4jdbc or p6spy as it is a secured application and using this will create bigger problems..toString won't work as I am using Oracle? I can't change PreparedStatement to Statement either.

有什么方法可以从 PreparedStatement 获取 Oracle 查询。我知道这是不可能的,因为我不能使用 log4jdbc 或 p6spy,因为它是一个安全的应用程序,使用它会产生更大的问题..toString 不会像我一样工作使用甲骨文?我也不能将 PreparedStatement 更改为 Statement 。

回答by pinichi

If only need for debug time then You can use DebuggableStatement follow this article

如果只需要调试时间那么你可以使用 DebuggableStatement 按照这篇文章

回答by Thilo

I don't think you should be doing it this way, as there is no officially documented API for this.

我认为您不应该这样做,因为没有正式记录的 API。

If you can mess with the code, why cannot you use log4jdbc ? Oracle JDBC also supports java.util.logging, which you could try to enable.

如果您可以弄乱代码,为什么不能使用 log4jdbc ?Oracle JDBC 还支持 java.util.logging,您可以尝试启用它。

If you are just interested in the SQL itself, you can turn on session tracing on the Oracle server.

如果您只是对 SQL 本身感兴趣,您可以在 Oracle 服务器上打开会话跟踪。

Or maybe you can put your code to where the statement is being prepared (using something like @pinichi is suggesting)?

或者,也许您可​​以将代码放在准备语句的位置(使用类似@pinichi 建议的内容)?

But just for fun, poking around with the debugger, with my version of Oracle JDBC, I can do

但只是为了好玩,使用调试器,使用我的 Oracle JDBC 版本,我可以做到

  if (stmt instanceof oracle.jdbc.driver.OraclePreparedStatement) {
        String x = ((oracle.jdbc.driver.OraclePreparedStatement) stmt)
             .getOriginalSql();
        System.out.println(x);
  }

回答by Lukasz Stelmach

If you just want to check SQL statement you can also go straight to the database and check v$sqltable.

如果只是想查SQL语句,也可以直接去数据库v$sql查表。

There you can find all sqls and other information about query. More info: http://download.oracle.com/docs/cd/B19306_01/server.102/b14237/dynviews_2113.htm

在那里您可以找到有关查询的所有 sql 和其他信息。更多信息:http: //download.oracle.com/docs/cd/B19306_01/server.102/b14237/dynviews_2113.htm