On 5/4/2018 10:38 AM, Phil Steitz wrote: > The only thing close to this that you can do now is if you have > prepared statement pooling enabled, then via the JMX instrumentation > of commons pool you can see the output of statement.toString(). > See listAllObjects in GenericObjectPoolMXBean. Again, the pool you > need to walk to get this is the prepared statement pool associated > with an individual connection, not the connection pool.
Is this an answer to both parts of my query? Only the second part was concerned with prepared statements. The first part was about getting currently executing SQL queries from BasicDataSource. I am not using prepared statements at this time. I will not be using them anytime soon. The plan that includes prepared statements is a complete rewrite of the application from scratch, to eliminate some design problems. I was using PoolingDataSource in the past. Because setting that up involves explicitly configuring the object pool, I did have access to listAllObjects, but since switching to BasicDataSource (which appears to be the recommended choice), that no longer seems to be available. The "setAccessToUnderlyingConnectionAllowed" method implies that it should be possible to access the connections ... but I can't figure out how to do that. Even if I manage that, I haven't yet found a way to descend from the connection to get the query. I acknowledge the possibility of an XY problem here, so here's what I'm trying to do: When my application fires off an alarm email, I want that email to include all SQL queries the application is executing at the moment of the alarm. Because all DB access is coordinated through a single class (which I creatively called "Database"), I can probably invent my own way of tracking this info, but if I can do it through dbcp, that's one less thing I have to write/debug. The alarm subroutines can only reach things that have access to the datasource, not anything below that. I think the way I would do it myself is using a Map<Connection, String> object built with Collections.synchronizedMap. When I close a connection (return it to the pool), I can remove its entry from that tracking map. Thanks, Shawn --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
