java中用两个视图连接查询,返回list,怎么循环取出list的数据

返回任意一个视图的对象都不对的了,那我应该返回什么?要再建一个这样的类吗?

可以返回一个map,然后从map中取值追问

我试过,返回map报错了,说只能返回object.因为list用hibernate做过分页处理

追答

hibernate的sql可以这么写,参考一下吧

select new map(a.id,c.id3,c.id2,a.id2)from eee a,bbbc where XXX

return 一个List

追问

我把得到的数据第条都存在Map里面,就是map里面的value值是一条数据来的了,然后我再怎么把这条数据里需要的字段值获取出来?
map.get("nt"+i).getClass().forName("pk1")
这样写不能获取的么?

追答

select new map(a.id,c.id3,c.id2,a.id2)from eee a,bbbc where XXX

取的时候

map.get("0")======>a.id(赋值的字段)
map.get("1")=======>c.id3
........
map.get("3")========a.id2

温馨提示:答案为网友推荐,仅供参考
第1个回答  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;
你可以研究一下,不需要在建类的

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网