This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes jboss complaining about cached connection not being closed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "jboss complaining about cached connection not being closed" Watch "jboss complaining about cached connection not being closed" New topic

jboss complaining about cached connection not being closed

Sergio Barreros

Joined: Sep 09, 2003
Posts: 21
Hello, I have a session ejb where I explicitly open and close a connection to my database, yet when I call that ejb and a result is returned the server complains about my connection not being closed.
Here is my EJB

userObj usr = new userObj();
if (userid.equals(null) | userpasswd.trim().equals("")) {
return null;
String sql = "select * from users " +
"where userid = '" + userid + "' " +
"and userpasswd = '" + userpasswd + "'";
try {
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("java:/support");
Connection con = ds.getConnection();
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sql);

if ( {
} else {
usr = null;

} catch (javax.naming.NamingException _ne) {
System.out.println("DataSource: Naming Exception!");
} catch (java.sql.SQLException _se) {
System.out.println("SQL Exception: " + sql);
} finally {

return usr;

AND here is part of the error message
Thanks in advance for any help..

16:44:43,918 INFO [CachedConnectionManager] Closing a connection for you. Plea
se close them yourself: org.jboss.resource.adapter.jdbc.WrappedConnection@3bbcfd

java.lang.Throwable: STACKTRACE
at org.jboss.resource.connectionmanager.CachedConnectionManager.register
at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateC
at org.jboss.resource.connectionmanager.BaseConnectionManager2$Connectio
at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(Wrapp
at hd.ejb.HelpDeskBean.Login(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
Jeanne Boyarsky
internet detective

Joined: May 26, 2003
Posts: 30068

Not sure if this causing the warning but the connection should be closed in the finally block so it happens even if an exception is thrown.

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
I agree. Here's the link:
subject: jboss complaining about cached connection not being closed
Similar Threads
Could not create connection !!!!
problem in connectivity through datasource to oracle database
Getting a "connection is already closed" exception with 2 or more users
login page for web portal
Database access, potential threading problem?