You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to log4jdbc
Arthur:
I had a need for support to enable my JPA application to retrieve the
SQL sent to the database (never mind why - you wouldn't believe it if
I told you). I found the following to work OK:
public class SpiedUponDataSource implements DataSource
{
private DataSource realDataSource;
public SpiedUponDataSource(DataSource realDataSource)
{
this.realDataSource = realDataSource;
}
public Connection getConnection() throws SQLException
{
return new ConnectionSpy(realDataSource.getConnection());
}
public Connection getConnection(String username, String password)
throws SQLException
{
return new ConnectionSpy(realDataSource.getConnection(username,
password));
}
// ... all other methods simply delegate to realDataSource
In Spring, this is very simple to set up (I'm retrieving my datasource
from Tomcat JNDI):
I don't like the class name, but otherwise, this seems to work just
fine. Now I have to figure out how to configure SLF4J to just return
the SQL statement to me (the one with the substituted values - really
like that feature!). Any advice about that, perchance?
David Sills
Arthur Blake
unread,
Jun 8, 2009, 9:40:52 AM6/8/09
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
Then write your own SpyLogDelegator instance. This way you can do
anything you want with the SQL. If you still want to log SQL to
SLF4J, your SpyLogDelegator could extend the Slf4jSpyLogDelegator and
just override the method(s) you are interested in, calling super at
the beginning of the methods.