0

I've developed a HTTP Servlet which connects to an Oracle Database. On my Weblogic logs, I get the error : Cannot obtain XAConnection weblogic.common.resourcepool.ResourceLimitException: No resources currently available in pool Kitry_InWebo to allocate to applications, please increase the size of the pool and retry.

I suspect my application to not release Database connection so, after a while, there are no more connection available.

My questions is how do I manage my DB connexion inside my HTTP Servlet ?

For the moment, I init Datasource in the init method:

ds = (DataSource)ic.lookup(dataSourceName);

then in the doGet method I open a new connection, execute a statement and close the connection:

// Get a DB connection  
conn = ds.getConnection(); 
stmt = conn.createStatement();  

// Execute Statement 
rs = stmt.executeQuery("select * from dual");             
while (rs.next()) {
  staffCode = rs.getString(1); 
}
conn.close();

It seems to be a good approach but I reach the maximum number connection. So what's wrong ?!

Regards,

Arnaud Denoyelle
  • 29,980
  • 16
  • 92
  • 148
Tim
  • 83
  • 2
  • 7
  • Do you sometimes get somes exceptions which would prevent from accessing the `conn.close()`? In this case, use a `try-with-resources`. (And even if you do not get some exception, `conn.close()` *must* be in a `finally` statement.) – Arnaud Denoyelle Feb 04 '16 at 17:06
  • Thanks for your answer. I finally found the exact issue. I had declared the connection variable in the class itself. So when the first call to my servlet called the conn.close(), the second simultaneous call to my servlet raised an error when calling the conn.close() because the first one had already closed it. I finally did like you said and I have used the Finally statement in which I close the connection. – Tim Feb 08 '16 at 13:39

0 Answers0