public String[] selectInfo()
{
Connection conn = null;
ResultSet rs = null;
PreparedStatement pstm = null;
String[] strs = new String[3] ;

try {

conn = DbUtil.getConn();

String sql = "select * from users";

pstm = conn.prepareStatement(sql);

rs = pstm.executeQuery();

while(rs.next())
{
strs[0] = rs.getString("name") ;
strs[1] = rs.getString("pwd") ;
strs[2] = rs.getString("school") ;
}

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally
{
try {
rs.close();
pstm.close();
conn.close();
} catch (Exception e) {
// TODO: handle exception
}
}

for (String it:strs) {

System.out.println(it);

}

return strs;
}说明:这个是一个数据库查询操作,我把查询的结果放到一个数组里面,然后返回数组,我在这个方法里面遍历了下数组,可只给我打印出数据库里最后一条数据。数组返回的时候也是数据库里最后一条数据。如果在while循环里面遍历数组的话,肯定能全部输出来。但是为什么遍历到while循环外面就只能得到最后一条数据呢?而且返回的时候也是一条数据。请高手告诉下。谢谢!