0

I have a question that puzzles me these days. I am using JDBC connection pool in oracle weblogc server for my REST API calls. The package was deployed and was able to handle the incoming requests correctly.

But somehow, after a new request is made, in the db session level, I will get a new session row of "INACTIVE" status, even if I have purposely have the db connection closed in the code. And seems to me, this session will kept for ever. Eventually it kills the pool.

Here is the sample of my code, where "apple" is my connection pool name.

    Connection connection = JDBCConnection.getJDBCConnction(apple);
    Statement stmt = null;
    String query ="select name from user";
    String hosts="";
    try {
        stmt = connection.createStatement();
        ResultSet rs = stmt.executeQuery(query);
        while (rs.next()) {
            name   = rs.getString("name");
        }
    } finally {
        connection.close();
    }

Is there anything extra I need to do ?

Thanks,

Jack

user3595231
  • 711
  • 12
  • 29
  • Its normal to have inactive session. When you are done with your connection and close it, it goes back to the pool but is not closed. Actually it is inactive thats why you see the inactive status. However, regarding your code, you should close your Statement and ResultSet because closing the connections in a pool just sent it back to the pool. – Rouliboy May 23 '17 at 20:45
  • But since it is being accumulated, then in which way do we expect them to be recycled ? – user3595231 May 23 '17 at 21:31
  • do you mean that you have more session created than the pool size? – Rouliboy May 23 '17 at 21:40
  • Yes. The problem I have is each incoming request, will add a new row in the session table. and in the end, my DB server no longer have any handler for any db connection. – user3595231 May 23 '17 at 21:46

1 Answers1

0

You are likely running into an issue where you are closing the Connection but it does not result in closing the ResultSet or the Statement.

The topic has been explained extensively here and here on SO.

radimpe
  • 3,197
  • 2
  • 27
  • 46