How can I get all data in Mysql DB with JAVA
I Have this code but he get only first row
if (connection != null) {
System.out.println("You made it, take control your database now!");
Statement st = connection.createStatement();
String sql = ("SELECT * FROM nc;");
ResultSet rs = st.executeQuery(sql);
if(rs.next()) {
int id = rs.getInt("id");
String str1 = rs.getString("Name");
String str2 = rs.getString("City");
System.out.format("%s, %s, %s\n", id, str1, str2);
and i get in the screen : id 0 , Name Nizar, City Casablanca
so how ican get all rows in my database and thank you
while(rs.next())