mysql rs.next()无法读取数据库表第一行的数据

sunny冰青 发布于 2015/03/23 20:52
阅读 696
收藏 0

/**

代码片段,根据输入的 String 型的account ,返回数据库表verification的部分信息,以ArrayList形式存储

*/

public ArrayList<HashMap<String,Object>> getBuddyList(String account) 


 //  int i = 0;
 //  ArrayList<String> list = new ArrayList<String>();
   ArrayList<HashMap<String,Object>> resultlist = new ArrayList<HashMap<String,Object>>();
 //  String[] array = null;
Connection connection = null;
try 
{
String ql = "select * from verification";
connection = DatabaseUtils.getDatabaseUtils().getConnection();
PreparedStatement pre = connection.prepareStatement(ql);
ResultSet rs = pre.executeQuery();
System.out.println("-------rs!=null--------"+(rs!=null));
System.out.println("-------rs.next()--------"+(rs.next()));
// String[] s = new String[]{"abc","asd","qq","qwer"};
while(rs.next())
{
System.out.println("------resultSet.getString account :--------"+(rs.getString("account").equals(account)));
//if(rs.getString("account").equals(account))
//{
System.out.println("------resultSet.getString account :--------"+(rs.getString("account")));
System.out.println("------resultSet.getString nick :--------"+(rs.getString(3)));
System.out.println("------resultSet.getString trends :--------"+(rs.getString(5)));
HashMap<String,Object> map = new HashMap<String,Object>();
map.put("account", rs.getString("account"));
map.put("nick", rs.getString("nick"));
map.put("avatar", rs.getInt("avatar"));
map.put("trends", rs.getString("trends"));
map.put("sex", rs.getString("sex"));
map.put("age", rs.getInt("age"));
map.put("lev", rs.getInt("lev"));
resultlist.add(map);
//}
//i++;
}

catch (ClassNotFoundException e)
{

e.printStackTrace();

catch (SQLException e) 
{

e.printStackTrace();
}
finally
{

try 
{
DatabaseUtils.getDatabaseUtils().closeConnection(connection);

catch (SQLException e) 
{
// TODO Auto-generated catch block
e.printStackTrace();
}

}
return resultlist;
}
加载中
0
t
ttqq

System.out.println("-------rs.next()--------"+(rs.next()));


s
sunny冰青
谢谢,我已经解决了
0
萧羽
楼上的看的仔细,
返回顶部
顶部