0

I want to use plain JDBC in a REST Service but the Connections are not returned to the Pool.

With the code below the second request will endup with pool exhausted. When i remove the '@Transactional' - it works - but it has no transaction and so no commit.

Any suggestion what is missing?

These are the Maven Dependencies:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-autoconfigure</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jta-atomikos</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>

Here is the REST Controller:

@RestController
@RequestMapping(value = "/demo")
@RequestScoped
public class Controller {

    @Autowired
    @Qualifier("IMSDB")
    DataSource imsdb;

    @Autowired
    @Qualifier("SQLDB")
    DataSource sqldb;

    @RequestMapping("")
    @Transactional
    public String index() throws SQLException, SystemException, NotSupportedException, HeuristicRollbackException, HeuristicMixedException, RollbackException {
        Connection icon = imsdb.getConnection();

        Statement s = icon.createStatement();
        s.execute("select 1 from sysibm.sysdummy1");
        s.close();

        Connection con = sqldb.getConnection();

        Statement s2 = con.createStatement();
        s2.execute("select 1 from sysibm.sysdummy1");
        s2.close();

        icon.close();
        con.close();
        return "dd";
    }
}

0 Answers0