我怎样才能获得在MySQL数据库中的所有数据与JAVA怎样才能从表中的所有数据在MySQL数据库与Java
我有这样的代码,但他得到的只有第一排
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);
和我得到在屏幕上:ID为0,名称尼扎尔,城市卡萨布兰卡
所以ICAN如何得到我的数据库中的所有行,并感谢您
use'while(rs.next())' – andreih