I'm trying to create an ArrayList based on the ResultSet. Using the while loop to iterate through all the rows I can get only the first row (With rs.next() and rs.first()) as well as the last one (rs.last()).
public ArrayList retrieveFromDb(Statement myStmt){
try{
ArrayList<String> inner = new ArrayList<>();
String query = "SELECT * FROM product";
ResultSet rs = myStmt.executeQuery(query);
while(rs.next()){
System.out.println(rs.getString("barcode"));
inner.add(rs.getString("barcode"));
System.out.println("done");
return inner;
}
} catch (SQLException ex) {
Logger.getLogger(Product.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
What I need is for the ArrayList to get the information from all the rows.
UPDATE: It looks like I failed to properly return the list by returning it too early (as pointed out in the answer below.)