用jdbc查询数据库中的东西,只能查出一条结果集,不能查出所有的结果集是为什么
public Map<String,String> findAll() throws ClassNotFoundException, SQLException{
//连接数据库
Connection connection=getConnection();
String sql="select * from user";
Statement statement=connection.createStatement();
//ps=connection.prepareStatement(sql);//使用Connection的方法创建PrepareStatement语句对象,该对象用来传送SQL语句
//ResultSet rs=ps.executeQuery(sql);
ResultSet rs=statement.executeQuery(sql);
Map<String,String> map=null;
System.out.println("rs :" + rs.getRow());
while(rs.next()){
map=new HashMap();
map.put(rs.getString(1), rs.getString(2));
}
//这个map集合遍历不出来
for(Map.Entry<String, String> me:map.entrySet()){
System.out.println(me.getKey()+"----->"+me.getValue());
}
return map;
}