Why isn’t my includeThreadNamesAsStatementComment JDBC parameter working?

Posted on

Question :

The JDBC API lists a includeThreadNamesAsStatementComment parameter that seems to indicate it will prefix all queries with the Java thread ID. I thought this would be useful in tying back DB activity to application logs. I added it to my resource URLs and it seemed to only be working part of the time.

Curiously it was only the applications heartbeat thread that periodically pings the database as part of a health check. None of the “real” queries were getting tagged.

Why isn’t this working for all queries?

Answer :

It turns out there’s a known bug where this only works when calling the the JDBC API directly. It does not work when building queries through something like SimpleJDBCTemplate. All of the applications real work was being done using templates whereas the healtcheck threads were using the direct API.

Leave a Reply

Your email address will not be published. Required fields are marked *