Here is the code snippets.
Below is the getConnection which returns Connection object public void init(String resourceId, String resourceName, boolean defaultResource) throws DBException { try { Context initCtx = new InitialContext(); Context envCtx = (Context) initCtx.lookup("java:comp/env"); this.m_sources.put(resourceId, envCtx.lookup(resourceName)); if (defaultResource) { this.m_defaultResourceId = resourceId; } } catch (NamingException ne) { throw new DBException(ne); } } public Connection getConn(String resourceId) throws DBException { if (resourceId == null) { resourceId = this.m_defaultResourceId; } try { DataSource dataSource = (DataSource) this.m_sources.get (resourceId); if (dataSource == null) { m_logger.error("###### FATAL ERROR -- DATA SOURCE NULL #######"); } Connection conn = dataSource.getConnection(); if (conn == null) { // try again???? conn = dataSource.getConnection(); if (conn == null) { m_logger.error("###### FATAL ERROR -- CONNECTION NULL #######"); } } conn.setAutoCommit(true); return conn; } catch (SQLException se) { throw new DBException(se); } } Below is the code where we call getConnection to the connection object. We are getting NullPointer where we do conn.close(). The thing that I am wondering is if we are getting null conn, we should get null pointer at conn.setAutoCommit in getConnection or conn.createStatement. But instead we are getting on conn.close public void doSelect(String p_sql, int[] p_dataTypes) throws DBException { Connection conn = null; Statement sqlStmt = null; ResultSet resultSet = null; RecSet recset = new RecSet(this.m_resourceId); try { conn = DBConnMgr.getInstance().getConn(this.m_resourceId); // The above code getConn which is pasted above if (conn != null) { m_logger.info("@@@@ We got the connection object"); } else { m_logger.info("######## DBSelect.doSelect CONNECTION IS NULL!!! ########"); } sqlStmt = conn.createStatement(); /* if (p_dataTypes != null) { for (int i = 0; i < p_dataTypes.length; i++) { //sqlStmt.defineColumnType(i+1, p_dataTypes); } } */ resultSet = sqlStmt.executeQuery(p_sql); //operate on resultSet here } catch (SQLException se) { if (DBConnMgr.getInstance().isFatalError(se)) { throw new DBException("Exception: " + se + ": " + se.getErrorCode() + "\n" + "Database is down " + "\n", se.getErrorCode()); } else { throw new DBException("Exception: " + se + ": " + se.getErrorCode() + "\n" + "Could not perform " + p_sql + "\n"); } } finally { try { if (resultSet != null) { resultSet.close(); } if (sqlStmt != null) { sqlStmt.close(); } } catch (SQLException se) { throw new DBException("Exception: " + se + "\n" + "Could not close sql statement" + "\n"); } finally { try { conn.close(); } catch (SQLException se) { m_logger.info("Failed to close DB connection"); } } } m_logger.debug("Successful " + p_sql + "\n"); } Thanks for the assistance View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4018868#4018868 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4018868 _______________________________________________ jboss-user mailing list jboss-user@lists.jboss.org https://lists.jboss.org/mailman/listinfo/jboss-user