---
title: "JDBC Instrumentation"
description: "Learn how to capture tracing information from database queries executed with JDBC."
url: https://docs.sentry.io/platforms/java/tracing/instrumentation/jdbc/
---

# JDBC Instrumentation | Sentry for Java

Capturing transactions requires that you first [set up tracing](https://docs.sentry.io/platforms/java/tracing.md) if you haven't already.

Sentry JDBC integration provides the `SentryJdbcEventListener` for [P6Spy](https://github.com/p6spy/p6spy/) database activity interceptor, which creates a span for each JDBC statement executed over a proxied instance of `javax.sql.DataSource`.

### [Install](https://docs.sentry.io/platforms/java/tracing/instrumentation/jdbc.md#install)

```xml
<dependency>
    <groupId>io.sentry</groupId>
    <artifactId>sentry-jdbc</artifactId>
    <version>8.37.1</version>
</dependency>
```

For other dependency managers, check out the [central Maven repository](https://search.maven.org/artifact/io.sentry/sentry-jdbc).

### [Configure](https://docs.sentry.io/platforms/java/tracing/instrumentation/jdbc.md#configure)

Configure the `DataSource` to use `com.p6spy.engine.spy.P6SpyDriver` as a JDBC driver. For Spring Boot applications:

```properties
spring.datasource.driver-class-name=com.p6spy.engine.spy.P6SpyDriver
```

Add the `p6spy` prefix to the database connection URL. For Spring Boot applications:

```properties
spring.datasource.url=jdbc:p6spy:postgresql://localhost:5432/db
```

P6Spy uses a Java [Service Loader](https://docs.oracle.com/javase/tutorial/sound/SPI-intro.html) mechanism to register `JdbcEventListener`s. For more configuration options, check the [P6Spy Reference Guide](https://p6spy.readthedocs.io/en/latest/).

### [Disable Log File Generation](https://docs.sentry.io/platforms/java/tracing/instrumentation/jdbc.md#disable-log-file-generation)

In addition to spans, P6Spy logs JDBC statements to a log file by default. Because this file can grow rapidly, we recommend disabling creating a log file by setting a system property `p6spy.config.modulelist` to `com.p6spy.engine.spy.P6SpyFactory` or creating a `spy.properties` file in `src/main/resources` with the content:

```properties
modulelist=com.p6spy.engine.spy.P6SpyFactory
```
