Umieść wartości zestawu wyników w obiekcie Collection, a następnie dodaj do ArrayList
Przetwarzałem mojeresultset
aby uzyskać szczegóły. Muszę zwrócićArrayList
, więc jak mogę umieścić klucz, wartości zresultset
do dowolnego z obiektów kolekcji, a następnie umieść to samo naArrayList
?
Oto kod:
public List<Bike> addBikes() throws ClassNotFoundException, SQLException{
List<Bike> bikeList = new ArrayList<Bike>();
Class.forName("com.mysql.jdbc.Driver");
Connection con = null;
Statement stm = null;
ResultSet rs = null;
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/spring_hibernate","root","root"); ;
stm=con.createStatement();
String qry="Select * from bike";
rs=stm.executeQuery(qry);
while(rs.next())
{
/* I need to put
* rs.getString("name"),rs.getString("model")
* etc into any of the suitable collection objects
* and then need to add those to the ArrayList - bikeList
*
*/
}
return bikeList;
}