开发者社区> 问答> 正文

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

`/**

代码片段,根据输入的 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;
}

展开
收起
小旋风柴进 2016-03-11 11:01:46 3472 0
1 条回答
写回答
取消 提交回答
  • System.out.println("-------rs.next()--------"+(rs.next()));

    2019-07-17 18:58:42
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
One Box: 解读事务与分析一体化数据库 HybridDB for MySQL 立即下载
One Box:解读事务与分析一体化数据库HybridDB for MySQL 立即下载
如何支撑HTAP场景-HybridDB for MySQL系统架构和技术演进 立即下载

相关镜像