0

I am using Prepared Statement Query. But I want to know the exact sql query before it gets executed.

The Database which I am using is ORACLE

Please Suggest Any ideas .

Paakiya
  • 11
  • 1
  • 5
  • Maybe [P6Spy](https://github.com/p6spy/p6spy) is appropriate? – Abra Nov 14 '21 at 13:30
  • 1
    In general, it is difficult to do this, because the parameters are actually bound to the statement on your Oracle database, not in your Java code. Why do you have this requirement? – Tim Biegeleisen Nov 14 '21 at 13:30
  • https://developer.ibm.com/articles/j-loggable/ – JCompetence Nov 14 '21 at 13:39
  • The exact SQL query being executed is the same that you've passed to the `PreparedStatement`. It doesn't change. The values of variables **are not part of the statement** (it has been [parsed](https://docs.oracle.com/en/database/oracle/oracle-database/19/cncpt/sql.html#GUID-B3F2B5B8-B679-4A7C-B1E8-286F36319FCB) already), they are the data that will be passed to the database for processing. So you may log them and then do what you want. – astentx Nov 14 '21 at 14:05
  • And appropriate logging is another task, because when you use, for example `select :num_var + 1 as v from dual`, and see just `1` in the log, then you cannot say if it was string or decimal or integer or some binary stream. But they are different for the database and may or may not produce an error at the execution. – astentx Nov 14 '21 at 14:17
  • @astentx So what is the way to get the sql of the prepared statement? – Paakiya Nov 16 '21 at 06:11

0 Answers0