Reputation: 2276
I am using JDBI to query MySQL in my java app. I want to log the metrics around the queries that are being performed on the app such as time spent by a query, the number of times a query was executed, time spend to obtain handle etc.. Although most of my queries are performed through a prepared statement, I have some queries where I pass the parameters in the query as part of SQL string. for example
select * from products where category in ('a', 'b', 'c') and id = :id;
JDBI logger outputs it as
select * from products where category in ('a', 'b', 'c') and id = ?;
it becomes very hard to group multiple queries to analyse it. Is there a library in java which can help me generalise such queries to like
select * from products where category in (?) and id = ?;
or maybe
select * from products where category in (?, ?, ?) and id = ?;
P.S. I know it is a really bad design to concat a string in SQL queries.
Upvotes: 0
Views: 409
Reputation: 142296
In MySQL, there are two approaches, both of which seem to meet your desires:
performance_schema
: https://dev.mysql.com/doc/refman/5.7/en/performance-schema.htmlI think both will do in (?, ?, ?) and id = ?
, and they use that as a "digest" of the query to summarize similar queries as to elapsed time, etc.
Upvotes: 0