title: com.microsoft.sqlserver.jdbc.SQLServerException: The connection is closed while taking the value of Resultset
body: <pre><code>public static ResultSet getTestDatafromSQL(String QueryString) throws SQLException {
      Connection conn = null;
      ResultSet resultSet = null;
      try {
          String dbURL = &quot;jdbc:sqlserver://localhost\\sqlexpress;DatabaseName=master;integratedSecurity=true;&quot;;
          conn = DriverManager.getConnection(dbURL);
          if (conn != null) {
              DatabaseMetaData dm = (DatabaseMetaData) conn.getMetaData();
              System.out.println(&quot;Driver name: &quot; + dm.getDriverName());
              System.out.println(&quot;Driver version: &quot; + dm.getDriverVersion());
              System.out.println(&quot;Product name: &quot; + dm.getDatabaseProductName());
              System.out.println(&quot;Product version: &quot; + dm.getDatabaseProductVersion().toString());
              Statement stmt = conn.createStatement();
              // Create and execute a SELECT SQL statement.
              resultSet = stmt.executeQuery(QueryString);
              System.out.println(resultSet);
              while(resultSet.next()) {
                  System.out.println(resultSet.getString(1));
                  //return resultSet.getString(1);
              }
          }
      } catch (SQLException ex) {
          ex.printStackTrace();
      } finally {
          try {
              if (conn != null &amp;&amp; !conn.isClosed()) {
                  conn.close();
              }
          } catch (SQLException ex) {
              ex.printStackTrace();
          }
      }
      return resultSet;
  }
          
  </code></pre>
  <p>Now In other class, I am calling that...</p>
  <pre><code>@Test(enabled = true)
  public void query() throws XPathExpressionException, IOException, SQLException {
      ResultSet sql = utilities.getTestDatafromSQL(&quot;SELECT ACCOUNT_NO1,CREDIT_LMT from [BCMASTER$] Where CAST(Trim(BCM_CREDIT_LMT) as float) &gt;5000&quot;);
      //System.out.println(sql.first());
      System.out.println(&quot;SQLValue:&quot;+sql.getString(1));
      System.out.println(&quot;SQLValue:&quot;+sql.getString(2));
  }
  </code></pre>
  <p>I am getting FAIL Sat Aug 15 10:25:24 IST 2020 com.microsoft.sqlserver.jdbc.SQLServerException: The connection is closed. - Test Case Failed</p>
  <p>To read the result set, db connection should be open?</p>
  <p>From each query I will get different columns, so is there any possible can we store it in array and return is only possibility or resultset can get the value?</p>