4

I need to log the SQL execution times in my Java EE application (Any further statistics would be an optional bonus).

Things are setup in a more-less standard way: Datasource on Application server serving pooled JDBC connections.

Application uses for DB access mix of:

  • Hibernate and
  • Spring JDBCTemplate

It runs on:

  • Glassfish OSE and
  • Oracle DBS

I know about: Anything better than P6Spy? however the question/answers are outdated, from my point of view.

What I've found so far:

Recommendations based on experiences are very welcome.

Please note, I'm interested in kind of answers like: We're using XYZ and this is our experience, rather than I googled just now and feel like...

Community
  • 1
  • 1
Peter Butkovic
  • 11,143
  • 10
  • 57
  • 81

3 Answers3

2

If you want dead accurate SQL execution time then best option is sql trace. But you want to put it in your Java EE application, so obviously want a somewhat accurate execution time.

Following are the things i would suggest [I have implemented them in my code]:

  1. If you just want it for loggin purpose then have appropriate Log4j debug messages which wil l print time along with log entry.

  2. I implemented a BatchLog table for my application which use to record start and end time of the operation. So in your case it will be start and end time of your query. Now if it is just a single query then probably triggers might help here or else you can update log table just before and after running query. Or even better will be a stored procedure which can take care of whole thing and give more accurate data.

Mike Braun
  • 3,729
  • 17
  • 15
Lokesh
  • 7,810
  • 6
  • 48
  • 78
1

Measuring time and logging it seems like a job for AOP. If you are using EJB, a simple interceptor should solve your problem(for example http://www.javacodegeeks.com/2013/07/java-ee-ejb-interceptors-tutorial-and-example.html). If its Spring(judging from JDBCTemplate), try Aspectj.

awb
  • 324
  • 2
  • 9
  • thanks for idea, I was rather looking for some reusable component, that I could just "plug&play" into my infrastructure. let's see if some other ideas come up – Peter Butkovic Aug 16 '13 at 11:21
  • well, I checked deeper, but EJB interceptors seem not feasable, I'd like to log SQL execution times, EJB if far higher than that. On the other hand AspectJ might work for me. – Peter Butkovic Aug 22 '13 at 13:39
0

OK, thanks a lot for your answers. Finally I decided to go for the P6Spy with patches specific to our scenario.

Moreover, as I believe that the gap P6spy is filling still exists these days, I decided to participate in it's development (https://github.com/p6spy/p6spy). Feel free to report your issues or feature requests to: https://github.com/p6spy/p6spy/issues to make it fit your needs.

Peter Butkovic
  • 11,143
  • 10
  • 57
  • 81