今天在需要查询某些数据的时候,一直只能浏览一条数据
1 while (rs.next()) { 2 String title = rs.getString("title"); 3 String content = rs.getString("content"); 4 String time = rs.getString("time"); 5 String createPeople = rs.getString("createPeople"); 6 document = new Document(title, content, time, createPeople); 7 } 8 list.add(document);
后面我发现,是list.add()放错了地方,应该将list.add()放置在while(){}循环里面。
即正确的为:
1 while (rs.next()) { 2 String title = rs.getString("title"); 3 String content = rs.getString("content"); 4 String time = rs.getString("time"); 5 String createPeople = rs.getString("createPeople"); 6 document = new Document(title, content, time, createPeople); 7 list.add(document); 8 }