This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
There is not direct way to get the SQL being executed by the preparedstatement from the java side (unless you use JDBC driver wrappers like p6spy). You need to write some sort of reflection code to get the SQL. Here is what I did
1. Used debug to break on preparedstatement execute statement from IDE. Examined the preparedstatement object and figured out the sql is stored in which field.
2. Execute below code
This worked fine with Oracle JDBC driver. The fields may vary based on the DB & Driver.