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
rs.next()
will increment cursor in if
so if resultset has only one row returned by query then while
will move cursor again and no data will get print.Use do..while
loop instead.
if (rs.next()) {
do {
System.out.print(rs.getString("idUser") + " ,");
System.out.print(rs.getString("Name") + " ,");
System.out.print(rs.getString("Email") + " ,");
System.out.println(rs.getString("country") + " .");
}while (rs.next());
}