File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Java 8 in Action this week in the Java 8 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
Author

jboss complaining about cached connection not being closed

Sergio Barreros
Greenhorn

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 (rs.next()) {
usr.setEmail(Utils.convertNull(rs.getString("usremail")));
usr.setClearance(Utils.convertNull(rs.getString("userclearance")));
usr.setAcro(Utils.convertNull(rs.getString("useracro")));
usr.setName(Utils.convertNull(rs.getString("username")));
usr.setLname(Utils.convertNull(rs.getString("userlname")));
} else {
usr = null;
}

con.close();
ctx.close();
stmt.close();
} 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
Connection(CachedConnectionManager.java:290)
at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateC
onnection(BaseConnectionManager2.java:417)
at org.jboss.resource.connectionmanager.BaseConnectionManager2$Connectio
nManagerProxy.allocateConnection(BaseConnectionManager2.java:842)
at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(Wrapp
erDataSource.java:88)
at hd.ejb.HelpDeskBean.Login(HelpDeskBean.java:92)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29274
    
140

Sergio,
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: http://aspose.com/file-tools
 
subject: jboss complaining about cached connection not being closed
 
Similar Threads
Database access, potential threading problem?
problem in connectivity through datasource to oracle database
login page for web portal
Could not create connection !!!!
Getting a "connection is already closed" exception with 2 or more users