3

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.

5
  • Just log the queries you run. You can't just intercept queries. Commented Nov 25, 2013 at 15:26
  • @SotiriosDelimanolis I'm having problems with the parameter binding, so I need to see what's going to the DB. I may be wrong, but I'm pretty sure I've done this same thing with log4j and Spring a while ago, but now my setup is different. Commented Nov 25, 2013 at 15:29
  • 5
    Take a look at log4jdbc - code.google.com/p/log4jdbc Commented Nov 25, 2013 at 15:30
  • @SotiriosDelimanolis Maybe I AM wrong. Now I remember that Hibernate was involved. Maybe I was getting Hibernate to log, not JDBC. Anyway, I was hoping I could pull it off without having to install a special driver or an external logging framework. Commented Nov 25, 2013 at 15:43
  • Actually, it would be helpful as well to know if what I want to do (log JDBC with JUL) is possible at al. Commented Nov 25, 2013 at 15:43

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Right! I was refering to that exact Hibernate config in my comment to Sotirios. Too bad I'm not using Hibernate this time. Thanks anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.