1
我使用JDBC中的以下函數從數據庫中提取行。我在數據庫中有兩條記錄,但它只打印兩條記錄。這就是最後的記錄。爲什麼?重複記錄兩次
public List<Student> getRows() throws SQLException {
Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/something", "root", "root");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM student");
Student tmp = new Student();
while (rs.next()) {
tmp.setId(rs.getInt("id"));
tmp.setName(rs.getString("name"));
list.add(tmp);
}
return list;
}