Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jboss complaining about cached connection not being closed

 
Sergio Barreros
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34837
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic