我正在处理我resultset
以获取详细信息。我需要返回一个ArrayList
,那么如何将键、值从resultset
到任何集合对象,然后将其放入一个ArrayList
?
这是代码:
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;
}