0

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?

Pablote
  • 4,745
  • 9
  • 39
  • 46
  • Have a look at this question, http://stackoverflow.com/questions/23564383/how-to-print-the-sqlquery-annotation-in-jdbi-sql-api/30549524#30549524 – Manikandan Sep 06 '16 at 10:03

1 Answers1

3

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
JuanMoreno
  • 2,498
  • 1
  • 25
  • 34
Pablote
  • 4,745
  • 9
  • 39
  • 46
  • Use the following flag to redirect output to console -Dp6spy.config.appender=com.p6spy.engine.spy.appender.StdoutLogger Details here https://p6spy.readthedocs.io/en/latest/configandusage.html#command-line-options – JuanMoreno Sep 12 '22 at 18:06