收集发出的所有SQL的最简单方法 [英] simplest way to collect all SQL sent out
问题描述
由于许多原因,我不想公开(冗长而乏味的故事),因此需要捕获复杂应用程序与数据库的交互.该应用程序基于Spring/JdbcTemplate构建,我需要查找此应用程序发出的所有SQL.如何以最简单的方式做到这一点?
For many reasons I prefer not to disclose (long and boring story), I need to capture the interactions of a complex application with the Database. The application builds on top of Spring/JdbcTemplate and I need to find all the SQL sent out by this application. How can I do that in the simplest possible way?
创建JdbcTemplate的伪模拟实现似乎不合理.首先,JdbcTemplate是一个类,而不是一个接口.其次,它有一个很大的接口,这使得实现起来很繁琐.我正在考虑模拟DataSource
和Connection
来发送所有SQL,但是也许有更简单的方法可以做到这一点?
Creating a pseudo mock implementation of JdbcTemplate does not seem reasonable. First off JdbcTemplate is a class and not an interface. Second it has a large interface that makes it tedious to implement. I am thinking along the lines of mocking DataSource
and Connection
to get all the SQL sent out, but maybe there is an easier way to do this?
推荐答案
这种问题很容易解决,例如. P6Spy .关于如何获取的方法,有好文章它与Spring兼容.
This kind of problem is very neatly solved be eg. P6Spy. There is a good article on how to get it working with Spring.
希望有帮助.
这篇关于收集发出的所有SQL的最简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!