sqlsql-serverdropwizardjdbi

Full SQL statement logging on Dropwizard


I've a Dropwizard application using JDBI and SQL Server. I would like to get all SQL statements logged with their parameters but I don't seem to be able to.

This is what's usually recommended to do: logging: level: INFO loggers: "org.skife": TRACE "com.microsoft.sqlserver.jdbc": TRACE

But this only logs statements, without the parameters:

TRACE [2016-07-08 16:40:27,711] org.skife.jdbi.v2.DBI: statement:[/* LocationDAO.detail */ EXEC [api].[GetCountryCodes] @CountryId = ?] took 487 millis DEBUG [2016-07-08 16:37:44,499] com.microsoft.sqlserver.jdbc.Connection: ENTRY /* LocationDAO.detail */ EXEC [api].[GetCountryCodes] @CountryId = ?

Is there any way to get the actual statement run against the database?


Solution

  • Using p6spy seems to be the easiest way to go. Just add the dependency:

    <dependency>
       <groupId>p6spy</groupId>
       <artifactId>p6spy</artifactId>
       <version>2.3.1</version>
    </dependency>
    

    On the database config, use the p6spy class instead and slightly modify your connection url

    database:
      driverClass: com.p6spy.engine.spy.P6SpyDriver
      url: jdbc:p6spy:sqlserver://10.0.82.95;Database=psprd1