title: SQLException: the result set is closed
body: <p>I am a beginner in Java using NetBeans and I was trying to create something similar to a faculty registration system. I use SQL Server 2005 to create the DB.
  During the implementation I was trying to create a function to make students able to register their subjects so the function basically searches for the subjects that the student has finished their prerequisites. So I wrote the following code:</p>
  
  <pre><code>package GUIs;
  import java.sql.*;
  import javax.swing.*;
  
  
  public class AddSubToStd extends javax.swing.JFrame {
  
  final void FillList1(){
      try{
      String url = "jdbc:sqlserver://localhost:1433;databaseName=BIS";
      String username = "sa";
      String password = "*****";
      Connection conn  = DriverManager.getConnection(url,username,password);
      Statement stmt = conn.createStatement();
      DefaultListModel DLM = new DefaultListModel();
      ResultSet res = stmt.executeQuery("SELECT * FROM Students");
      while(res.next()){
          DLM.addElement(res.getString("ID"));
      }
      List1.setModel(DLM);
  }
      catch(SQLException e){
          JOptionPane.showMessageDialog(null, e.toString());
      }
  }
  
  final void FillList2(){
      try{
      String url = "jdbc:sqlserver://localhost:1433;databaseName=BIS";
      String username = "sa";
      String password = "*****";
      Connection conn  = DriverManager.getConnection(url,username,password);
      Statement stmt = conn.createStatement();
      DefaultListModel DLM = new DefaultListModel();
      String Query = "SELECT * FROM FinishedCourses WHERE ID = '"+List1.getSelectedValue()+"'";
      ResultSet res = stmt.executeQuery(Query);
  
      ResultSet res1;
      String S_Code;
      String Query1;
  
      while(res.next()){
  
           S_Code = res.getString("S_Code");
           Query1 = "SELECT * From Subjects WHERE Prerequisite = '"+S_Code+"'";
           res1 = stmt.executeQuery(Query1);
  
          while(res1.next()){
  
              DLM.addElement(res.getString("S_Code"));
          }
  
      }
      conn.close();
      stmt.close();
      List2.setModel(DLM);
  }
      catch(SQLException e){
          JOptionPane.showMessageDialog(null, e.toString());
      }
  }
  
  public AddSubToStd() {
      initComponents();
      FillList1();
  
  }
  </code></pre>
  
  <p>but I get the <code>SQLException</code> that says the result set is closed when I try to invoke <code>FillList2()</code></p>
  
  <pre><code> private void UpdateAllowedActionPerformed(java.awt.event.ActionEvent evt) {                                              
      try{
      String url = "jdbc:sqlserver://localhost:1433;databaseName=BIS";
      String username = "sa";
      String password = "*****";
      Connection conn  = DriverManager.getConnection(url,username,password);
      FillList2();    
      }
      catch(SQLException e){
          JOptionPane.showMessageDialog(null, e.toString());
      }
  
  }                                 
  </code></pre>
  
  <p>someone please help.</p>