在 oracle.jdbc.driver.OraclePreparedStatement 中的 PreparedStatement 中打印 SQL 查询

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2781259/
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 20:34:44  来源:igfitidea点击:

Printing SQL Query In PreparedStatement in oracle.jdbc.driver.OraclePreparedStatement

oraclejdbcprepared-statement

提问by myahya

I need to see the query being sent to Oracle from a Java program. In the PostgreSQL JDBC driver, toString() does the job, but the same does not apply to prepared statements from Oracle JDBC implementation. Any ideas how to achieve that?

我需要查看从 Java 程序发送到 Oracle 的查询。在 PostgreSQL JDBC 驱动程序中, toString() 完成了这项工作,但同样不适用于来自 Oracle JDBC 实现的准备好的语句。任何想法如何实现这一目标?

回答by skaffman

Check out Log4Jdbc. This sits between your JDBC driver and the application, logging all DB traffic that goes back and forth. It's driver-agnostic, so need for driver-specific logging code.

查看Log4Jdbc。这位于您的 JDBC 驱动程序和应用程序之间,记录所有来回的数据库流量。它与驱动程序无关,因此需要特定于驱动程序的日志记录代码。

Extremely handy, and would be even handier if it supported DataSources, but sadly it doesn't.

非常方便,如果它支持 DataSources 会更方便,但遗憾的是它没有。

回答by Vincent Malgrat

I think the getOriginalSql()method returns the String being sent to Oracle.

我认为该getOriginalSql()方法返回发送到 Oracle 的字符串。