0

I'm using bonecp v0.8.0 (which I believe is the latest), paired with Mysql Connector/J 5.1.6

Suppose I have the following code

BoneCP pool = new BoneCP(...);
Connection origConn = pool.getConnection();
Statement origStmt = conn.createStatement();

...
ResultSet rs = origStmt.executeQuery(...);
...
Statement newStmt = rs.getStatement();
Connection newConn = newStmt.getConnection();
rs.close();
newStmt.close();
newConn.close();

In the above code, it seems that while origConn==newConn, origStmt!=newStmt. I found this odd.

I also found that if I close the newStmt, and not the origStmt, my connections tend to grow without ever being freed back into the connection pool. This ultimately leads to my app running out of connections and freezing (when it requests a new connection).

The javadocs leads me to believe that ResultSet.getStatement() returns me the same Statement object that created it, but maybe this is not the case with BoneCP.

Anyone know what's happening here?

kane
  • 5,465
  • 6
  • 44
  • 72
  • As per the javadoc of getStatement(), this code should throw a SQLException: *SQLException - if a database access error occurs or this method is called on a closed result set*. So, either your driver of BoneCP has a bug. – JB Nizet Feb 17 '16 at 19:12
  • I actually call getStatement() before I close the ResultSet. Sorry for the confusion. I've fixed the code snippet – kane Feb 17 '16 at 22:56
  • Which database backend driver do you use? Much depends on which JDBC driver is loaded and used by BoneCP. Please update the original question. – MWiesner Feb 18 '16 at 18:21
  • @MWiesner good catch. I'm using Mysql driver, v5.1.6 – kane Feb 19 '16 at 00:43
  • That is a pretty "old" version. See: http://dev.mysql.com/doc/relnotes/connector-j/en/news-5-1.html and find that you should latest 5.1.38 driver. If you have time: Read the changelogs since then... but maybe just try the latest driver version and report back if that fixes it or if the problem still exists. – MWiesner Feb 19 '16 at 08:13

0 Answers0