java中用两个视图连接查询,返回list,怎么循环取出list的数据
2个回答
2011-09-01
展开全部
String sql="select r_id,b_num,d_id from S_route where b_num=?";
Connection conn=DBUtil.getConnection();
PreparedStatement ps=DBUtil.getPreparedStatement(conn, sql);
ResultSet rs=null;
List<Route> list=new ArrayList<Route>();
try {
ps.setString(1, busnum);
rs=ps.executeQuery();
while(rs.next()){
Route route1=new Route();
Bus bus=new Bus();
Depot depot=new Depot();
route1.setId(rs.getInt(1));
bus.setNum(rs.getString(2));
route1.setBus(bus);
depot.setId(rs.getInt(3));
route1.setDepot(depot);
list.add(route1);
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
DBUtil.closeResultSet(rs);
DBUtil.closePreparedStatement(ps);
DBUtil.closeConnection(conn);
}
return list;
你可以研究一下,不需要在建类的
Connection conn=DBUtil.getConnection();
PreparedStatement ps=DBUtil.getPreparedStatement(conn, sql);
ResultSet rs=null;
List<Route> list=new ArrayList<Route>();
try {
ps.setString(1, busnum);
rs=ps.executeQuery();
while(rs.next()){
Route route1=new Route();
Bus bus=new Bus();
Depot depot=new Depot();
route1.setId(rs.getInt(1));
bus.setNum(rs.getString(2));
route1.setBus(bus);
depot.setId(rs.getInt(3));
route1.setDepot(depot);
list.add(route1);
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
DBUtil.closeResultSet(rs);
DBUtil.closePreparedStatement(ps);
DBUtil.closeConnection(conn);
}
return list;
你可以研究一下,不需要在建类的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询