Search code examples
javajdbcresultset

ResultSet how to put it into a ArrayList


Is "ResultSet" considered to be an ArrayList? I'm talking about jdbc. If no, then how do I put the information i get from my DB using the

while (result.next()) {
....

}

syntax into an ArrayList called something like hotelResult?

I hope it was understandable.


Solution

  • No, ResultSet is not considered an ArrayList but rather a table. If hotelResult for example has the type of String you can fill the list with this piece of code(if the column from the ResultSet is a String).

    while(result.next()) {
      hotelResult.add(result.getString("Enter the columnname here");
    }
    

    For each datatype there is a method to get the value from the ResultSet. Look in the Java API for the different kinds of methods.