Null Connection with jooq

25 views
Skip to first unread message

Walid CHAIB

unread,
Mar 29, 2021, 4:59:17 AM3/29/21
to jooq...@googlegroups.com
Why when I execute a query with jooq parsing connection I get
You can see in the attached files the code of the server and the connection :

- jOOQ:3.15
<dependency>
<groupId>org.jooq.pro</groupId>
<artifactId>jooq</artifactId>
<version>3.15.0</version>
</dependency>
<dependency>
<groupId>org.jooq.pro</groupId>
<artifactId>reactivestreams</artifactId>
<version>3.15.0</version>
</dependency>
- Java:8
- Database :Postgresql
- OS:open suse
- JDBC Driver:4.2
test
PostgreSQLDBCPDatasourceDbConnection.java
server.xml
exception.log

Lukas Eder

unread,
Mar 29, 2021, 7:26:09 AM3/29/21
to jOOQ User Group
Hi Walid,

- Whoever opens a JDBC Connection is responsible for closing it again
- Your example is now passing the DataSource to jOOQ, in case of which jOOQ will open *and* close the connection for you
- However, you also close the underlying (wrapped) JDBC connection explicitly in closeDbConn. You probably shouldn't do that
- I gave you that particular hint about a possible workaround in closeDbConn, because at the time, you were passing the *Connection* (not DataSource) to jOOQ, meaning *you* were opening the connection and *you* were responsible for closing it again. You cannot, however, close it via the jOOQ ParsingConnection, because the jOOQ ParsingConnection follows the jOOQ ConnectionProvider lifecycle, meaning that because you gave jOOQ a connection which *you* opened, jOOQ is assuming that *you* will close it again, not jOOQ.

I don't think there's a new question here, short of perhaps a misunderstanding of the above.

If you think there's a bug here somewhere, I'd love to investigate it, but as I told you, these kinds of issues are very hard to debug by email snippets. We have a template to create MCVEs (Minimal, Complete, Verifiable Examples): https://github.com/jOOQ/jOOQ-mcve.


--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jooq-user/CAOP4Xxin-Mw6jky9q-3O3pP3Fh6h6hYw3f4pDp%3DaS9x07KRbFg%40mail.gmail.com.

Walid CHAIB

unread,
Mar 30, 2021, 5:55:06 AM3/30/21
to jooq...@googlegroups.com
Hi Lukas,
Thanks again, You are alright.
Problem solved.

ahmed mustapha ghanmi

unread,
Apr 22, 2024, 10:14:14 AMApr 22
to jOOQ User Group
Hello everyone,

If I understand correctly, 
- if i pass a Connection to jooq to create a parsing connection, i need to close both the parsing connection and its underlying connection
- if i pass a data source to jooq, i need to only close the parsing connection, jooq handles the underlying connection 
Is that right?

Lukas Eder

unread,
Apr 22, 2024, 11:13:17 AMApr 22
to jooq...@googlegroups.com
This isn't specific to jOOQ, but is a general rule regarding resources. Whoever opens a resource must close the resource.

- A Connection is a resource, so you must close both in your first case
- A DataSource isn't a resource. It is used to create resources (Connections). jOOQ creates these internally, and will close them as necessary

I hope this helps
Lukas

Reply all
Reply to author
Forward
0 new messages