[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - Getting Error:closing a connection for you. Please help

rajikannan do-not-reply at jboss.com
Wed Oct 1 07:54:36 EDT 2008


Hello,
I'm using jboss3.2.6. I used ejb2.1 (session bean and entity bean[BMP]). I did few data base transations in cmp and few in simple data source connection.

I'm getting below errors occasionally
'No managed connection exception
java.lang.OutOfMemoryError: Java heap space
[CachedConnectionManager] Closing a connection for you.  Plea
se close them yourself: org.jboss.resource.adapter.jdbc.WrappedConnection at 11ed0d
5

I've given below my dao connection code here,

  | package com.drtrack.util;
  | 
  | import java.sql.Connection;
  | import java.sql.SQLException;
  | 
  | import javax.naming.Context;
  | import javax.naming.InitialContext;
  | import javax.naming.NamingException;
  | import javax.sql.DataSource;
  | 
  | public class DAOUtil {
  | 	
  | 	private static DataSource _ds;	  
  | 
  | 	public Connection con;
  | 	public DAOUtil() throws SQLException {
  | 		
  | 	  try {
  | 	    	
  | 	    if (_ds == null)
  | 	      assemble();
  | 	    if(_ds != null && con == null) {
  | 	    	
  | 	    	con = _ds.getConnection();
  | 	    	
  | 	    }
  | 	  }catch(SQLException ex) {
  | 	    	
  | 	    ex.printStackTrace();
  | 	    	
  | 	  }  
  | 	    
  | 	}
  | 
  | 	private void assemble() {
  | 	  Context ic = null;
  | 	  try {   	
  | 	    
  | 	    ic = new InitialContext();
  | 	    DrTrackUtil drutil = new DrTrackUtil();  
  | 	    _ds = (DataSource) ic.lookup("java:/" + drutil.getText("SOURCE_DIR"));
  | 	     drutil = null; 	      
  | 	  }catch (Exception e) {
  | 	    	
  | 	    e.printStackTrace();
  | 	    	
  | 	  }finally {
  | 		  try {
  | 			  ic.close();
  | 		  }catch(NamingException ne) {}
  | 	  }
  | 	    
  | 	}
  | 	
  |     public void closeConnection() throws SQLException {
  | 		
  | 		if(con != null)
  | 			con.close();
  | 		
  | 		con = null;
  | 	}
  | 	
  | }
  | 

below is the code with get connection and doing transaction in it.

  | 	public static AccountMasterValueBean getAccountMasterByAcctId(String acctId) {
  | 		
  | 	  AccountMasterValueBean bean = null;
  | 	  DAOUtil dao = null;
  | 	  CallableStatement cst = null;
  | 	  ResultSet rs = null;
  | 	  try {
  | 		  dao = new DAOUtil();  
  | 		  
  | 		  cst = dao.con.prepareCall(DrTrackConstants.MSSQL_USP_ACCOUNTMASTER_BY_ACCTID);
  | 		  cst.setObject(1, acctId);
  | 		  
  | 		  rs = cst.executeQuery();
  | 		  if(rs != null && rs.next()) {
  | 			  
  | 			  bean = new AccountMasterValueBean(
  | 					  Integer.valueOf(rs.getString("accountkeyid")), 
  | 					  rs.getString("latitude"), 
  | 					  rs.getString("longitude"));
  | 				
  | 		  }
  | 	  }catch(SQLException se) {
  | 		  logger.info("SQL Error: " + se); 
  | 	  }
  | 	  finally {
  | 				if(rs != null){
  | 				  try {
  | 					rs.close();
  | 				  }catch(SQLException se) {
  | 					  logger.info("SQL Error: " + se); 
  | 				  }
  | 				  finally {
  | 					  rs = null;
  | 				  }
  | 				}
  | 				if(cst != null) {
  | 				  try{
  | 					  cst.close();
  | 				  }catch(SQLException se) {
  | 					  logger.info("SQL Error: " + se);
  | 				  }
  | 				  finally {
  | 					  cst = null;
  | 				  }
  | 				}
  | 				if(dao != null) {
  | 			      try {
  | 			    	  dao.closeConnection();
  | 			      }catch(SQLException se) {
  | 			    	  logger.info("SQL Error: " + se);
  | 			      }
  | 			      finally {
  | 			    	  dao = null;
  | 			      }						
  | 				}
  | 	  }
  | 	  return bean;	
  | 	}
  | 

I closed connections, resultsets and statements properly. 
Why I'm getting these errors.? Where I'm doing wrong. ? Please help me. I have to fix them ASAP.

Thanks.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4179762#4179762

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4179762



More information about the jboss-user mailing list