title: How to convert ResultSet to string in Java
body: <p>I want to convert resultset to string. After that, I will use the string to write a html file.Course is a table contain courseid(String),name(String),prerequisites(String) connect database is ok. Here is my code and idea. Can you evaluate my idea or give me some better solution?</p>
  
  <pre><code>private static void printRecordFromCourse() throws SQLException {
      Connection dbConnection = null;
      Statement stmt = null;
      String printSQL = "SELECT * FROM course";
  
      try {
          dbConnection = getDBConnection();
          stmt = dbConnection.createStatement();
                      ResultSet rs=stmt.executeQuery(printSQL);
          while(rs.next()){
              //Retrieve by column name
              String courseid  = rs.getString("courseid");
              String name = rs.getString("name");
              String prerequisites = rs.getString("prerequisites");
  
              String result+ = "&lt;tr&gt;&lt;td&gt;"+courseid+"&lt;/td&gt;&lt;td&gt;"+name+"&lt;/td&gt;&lt;td&gt;"+prerequisites"&lt;/td&gt;&lt;/tr&gt;";
          }
          rs.close();
      } catch (SQLException e) {
          System.out.println(e.getMessage());
      } finally {
          if (stmt != null) {
              dbConnection.close();
          }
          if (dbConnection != null) {
              dbConnection.close();
          }
      }
  }
  </code></pre>