File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases 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
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
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
author & internet detective

Joined: May 26, 2003
Posts: 33119

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.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: jboss complaining about cached connection not being closed
It's not a secret anymore!