TopLink Wiki
Main
RecentChanges
Set your name in
UserPreferences
Referenced by
JSPWiki v2.0.52
|
Is there a way to view the SQL that would result from an Expression without actually executing the query via a session with logging turned on?First call query.prepareCall() then query.getSQLString(). When using parameter binding, the query is generated with "?" placeholders. Use q.getCall().getParameters() to get a hold of the parameter values. If you need to get the exact string, you can turn off parameter binding: q.dontBindAllParameters() for that particular query. Or use q.getTranslatedSQL() to get the SQL with the values populated where the "?" were. What I have seen people do who are super keen on doing this is they create their own implementation of the JDBC interface (it's actually not that difficult), and then just grab the SQL from their JDBC implementation. I remember a few years ago someone I knew simply wrote a wrapper for a JDBC connection that didn't forward the SQL and instead kicked it out to a log file. See LogSql. Another option is to reverse engineer the vendor's JDBC classes to find the point where the SQL string gets sent and log it.
See Also
TopLinkLogging, LogSql, forum:291135
|
||||||