各位大神,我要写一个方法查询数据库后返回一个集合这样写行么?如果不行,麻烦大神给出详细代码讲解!
publicStringgetListFromRs(ResultSetrs)throwsSQLException{Connectioncon=null;Statement...
public String getListFromRs(ResultSet rs) throws SQLException{
Connection con = null;
Statement stm = null;
String sql = "select Online_time,user_name from user_log" ;
con = getCon();
stm = con.createStatement();
rs = stm.executeQuery(sql);
Map<String,List<String>> map=new HashMap<String,List<String>>();
while(rs.next()){
String st = rs.getString("online_time");
List<String> list=map.get(st);
if(null==list){
list=new ArrayList<String>();
}
list.add(rs.getString("username"));
System.out.println(list);
}
return sql;
} 展开
Connection con = null;
Statement stm = null;
String sql = "select Online_time,user_name from user_log" ;
con = getCon();
stm = con.createStatement();
rs = stm.executeQuery(sql);
Map<String,List<String>> map=new HashMap<String,List<String>>();
while(rs.next()){
String st = rs.getString("online_time");
List<String> list=map.get(st);
if(null==list){
list=new ArrayList<String>();
}
list.add(rs.getString("username"));
System.out.println(list);
}
return sql;
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询