0

I am getting closed exception messages with my below jdbc connection to Oracle 9i from Tomcat 6 container. The database connection is used about once or twice a day.

java.sql.SQLException: Closed Statement
and
java.sql.SQLException: Closed Statement: next

private Connection connection;   
public ArrayList<MoneyBean> getMoneyList()   
{   
     ArrayList<MoneyBean> list = new ArrayList<MoneyBean>();   
     connection = new DatabaseConnector.getConnection();   
      
     if(connection != null)   
     {   
          ResultSet rs = null;   
          PreparedStatement preparedStatement = null;   
        
          try {   
               String BankQuery = "Select money from Bank";   
               preparedStatement = connection.preparedStatement(BankQuery);   
               rs = preparedStatement.executeQuery();   
               while(rs.next())   
               {   
                    MoneyBean money = new MoneyBean();   
                    money.setMoney(rs.getString("money"));   
                    list.add(money);   
               }   
          }   
      }   
      catch(SQLException ex)   
      {   
          System.out.println(ex);    
      }   
      finally  
      {   
         try  
         {    
            if(rs != null)   
            {    
                rs.close();    
            }    
          }    
          catch(Exception e)    
         {    
            e.printStackTrace();    
          }    
  
          try  
          {    
             if(preparedStatement != null)   
             {    
                preparedStatement.close();    
              }    
           }    
           catch(Exception e)    
          {    
              e.printStackTrace();    
          }    
  
          try  
          {    
            if(connection  != null)   
            {    
                connection.close();    
            }    
          }    
          catch(Exception e)    
          {    
            e.printStackTrace();    
          }       
     }   
return list;   
}

Any suggestions on how I can fix the SQLException Closed Statement issue?

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by javaAddict
0

I believe it maybe because you are doing preparedStatement.close & connection.close.... Do you have the complete stack trace?

0

There is a problem with your brackets. You do this:

if (conn!=null) {
  try {
  }
} catch () {

}

Whenever you open something close it immediately and then write inside it

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.