首页 > 技术文章 > sql结果集转成list集合

zhengzhongqi 2019-08-28 12:04 原文

ResultSet rsAll = con.executeQuery(sqlAll); 

List<preTime> listAll = convertList(rsAll); 

private static List convertList(ResultSet rs) throws SQLException {

List list = new ArrayList();
while(rs.next()){   
Integer id = rs.getInt("Id");
Double lat = rs.getDouble("Lat");
Double lon = rs.getDouble("Lon");
preTime preTime = new preTime();
preTime.setId(id);
preTime.setLat(lat);
preTime.setLon(lon);
//将对象存放到list容器中
list.add(preTime);
    }
return list;
}

推荐阅读