开发者

Query from PreparedStatement

Is there any way to get the Oracle query from PreparedStatement .开发者_StackOverflowI 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.


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


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

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.

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

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

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

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


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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜