# SQL Spans with DB2 (JDBC 4)

**URL:** <https://discuss.elastic.co/t/sql-spans-with-db2-jdbc-4/207319>\
**Category:** APM\
**Tags:** java\
**Created:** [November 11, 2019, 9:52am UTC](https://discuss.elastic.co/t/sql-spans-with-db2-jdbc-4/207319 "2019-11-11T09:52:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![skorhone](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/skorhone/32/57469_2.png) [@skorhone](https://discuss.elastic.co/u/skorhone)\
**Post date:** [November 11, 2019, 9:52am UTC](https://discuss.elastic.co/t/sql-spans-with-db2-jdbc-4/207319/1 "2019-11-11T09:52:53Z")

</div>

**APM Agent language and version** :  
Java / 1.11.0

**Is there anything special in your setup?** For example, are you using the Logstash or Kafka outputs? Are you using a load balancer in front of the APM Servers? Have you changed index pattern, generated custom templates, changed agent configuration etc.

DB2 (z/os)

**Description of the problem including expected versus actual behavior. Please include screenshots (if relevant)**:

Only the first query gets traced. No warnings are generated.

**Steps to reproduce** :

1. Create a minimal Spring boot 2 application
2. Add Ibm JDBC v4 drivers as dependency
3. Create a DB2 (z/os) Datasource
4. Create a scheduled bean, that invokes a simple query (e.g. select 1 from sysibm.sysdummy1) using prepared statement
5. Start application with java-agent attached

Are there known issues with jdbc tracing?

Source code for reproducing:

```
@RequestMapping("/hello")
@RestController
public class TestController {
	private DataSource ds;

	public TestController() {
		DB2SimpleDataSource ds = new DB2SimpleDataSource();
		ds.setServerName("db2.com");
		ds.setPortNumber(5100);
		ds.setDatabaseName("DB2DB");
		ds.setUser("DB2USER");
		ds.setPassword("DB2PASS");
		ds.setFetchSize(10);
		ds.setDriverType(4);

		this.ds = ds;
	}

	@GetMapping
	public String hello() throws Exception {
		try (Connection c = ds.getConnection();
				PreparedStatement ps = c.prepareStatement("select 1 from sysibm.sysdummy1", ResultSet.TYPE_FORWARD_ONLY,
						ResultSet.CONCUR_READ_ONLY);
				ResultSet rs = ps.executeQuery()) {
			rs.next();
		}
		return "hello";
	}

	@Scheduled(fixedDelay = 1000)
	public void scheduled() throws Exception {
		hello();
	}
}
```

---

<div class="post-metadata">

**Author:** ![Eyal\_Koren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eyal_koren/32/36830_2.png) [@Eyal\_Koren](https://discuss.elastic.co/u/Eyal_Koren)\
**Post date:** [November 12, 2019, 10:12am UTC](https://discuss.elastic.co/t/sql-spans-with-db2-jdbc-4/207319/2 "2019-11-12T10:12:43Z")

</div>

Hi Sami and welcome to the forum 🙂

Looks like you figured it out - [https://github.com/elastic/apm-agent-java/issues/925](https://github.com/elastic/apm-agent-java/issues/925). We will provide you with a fix applying your suggestion and see if that works.

---

<div class="post-metadata">

**Author:** ![Sylvain\_Juge](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sylvain_juge/32/55521_2.png) [@Sylvain\_Juge](https://discuss.elastic.co/u/Sylvain_Juge)\
**Post date:** [November 25, 2019, 12:57pm UTC](https://discuss.elastic.co/t/sql-spans-with-db2-jdbc-4/207319/3 "2019-11-25T12:57:48Z")

</div>

FYI, fix has been released in version [1.12.0](https://github.com/elastic/apm-agent-java/releases/tag/v1.12.0) of Java agent.

Thanks a lot @skorhone for reporting and helping us fix this issue.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 16, 2019, 8:57am UTC](https://discuss.elastic.co/t/sql-spans-with-db2-jdbc-4/207319/4 "2019-12-16T08:57:51Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
