Coloque os valores do conjunto de resultados no objeto Coleção e, em seguida, adicione ao ArrayList
Eu estava processando meuresultset
para obter os detalhes. Eu preciso devolver umArrayList
, como posso colocar a chave, valores doresultset
para qualquer um dos objetos da coleção e, em seguida, colocar o mesmo para umArrayList
?
Aqui está o código:
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;
}