0

My problem is that I would like to write all the queries called in my app into a log file. For example: here's a query:

String query = "SELECT * FROM users WHERE name LIKE 'Mike'";

I also have a Connection (DBConnect) object, with which I execute queries like this:

ResultSet myResultSet = DBConnect.getStatement().executeQuery(query);

Since there will be a lot of query call in the app, and more people are developing it, I would like to override the executeQuery method, in a way that before executing the query it would write the given query into a log file. And whenever an executeQuery method is called, it will log the query.

Thanks in advance

mordes
  • 73
  • 1
  • 1
  • 9
  • 1
    You forgot to ask an actual question. Be aware that although JDBC defines some form of logging, this is inconsistently implemented. You may want to look for something like [P6Spy](https://github.com/p6spy/p6spy) instead of trying to write your own. – Mark Rotteveel Oct 23 '18 at 15:46
  • Check the database driver - it might already support this type of logging. Be careful about logging [PII](https://en.wikipedia.org/wiki/Personally_identifiable_information). – Andrew S Oct 23 '18 at 15:48

0 Answers0