Avoiding skipping a row By next() Method of ResultSet

后端 未结 6 1995
野性不改
野性不改 2021-01-15 00:34

This is a simple code print some rows from a Database. but When I execute this nothing is print on screen. I figured that the problem is rs.next() method is ski

6条回答
  •  太阳男子
    2021-01-15 01:29

    Thanks for every answers. I found that putting rs.relative(-1) also does the job. But above answers are well coded and better than mine. So thanks all. I'm a newbie to programming I will consider all your advice in my coding. Thanks

    if (rs.next()) {
         rs.relative(-1);
            while (rs.next()) {
                System.out.print(rs.getString("idUser") + " ,");
                System.out.print(rs.getString("Name") + " ,");
                System.out.print(rs.getString("Email") + " ,");
                System.out.println(rs.getString("country") + " .");
            }
     }
    

提交回复
热议问题