Ricardo
Ricardo

Reputation: 818

How can I log JDBC database queries using java.util.logging?

I want to debug a few of my application JDBC queries so I wanted to configure java.util.logging to dump the actual SELECT statements that were run against the database and the data bound to their parameters.

I already have java.util.logging configured to log other messages to file. The setup code is as folloing:

Handler fh = new FileHandler("file.log", true);
Logger logger = Logger.getLogger("");
fh.setFormatter(new GruposLogFormatter());
logger.addHandler(fh);
logger.setLevel(Level.ALL);
logger.info("==================================");

So, how can I configure java.util.logging to log JDBC queries to a file or sysout?

This answer barely touches the subject, but didn't help me.

Upvotes: 3

Views: 4537

Answers (1)

Dev Blanked
Dev Blanked

Reputation: 8865

If you are using Hibernate following configurations can be done to get the sql queries printed.

How to print a query string with parameter values when using Hibernate

You can use http://sourceforge.net/projects/p6spy/ also and intercept all queries and log them to a file

Upvotes: 2

Related Questions