首先通过一个sql语句得到一个结果集,然后通过上面得到的结果再次查询,把这次查询的结果放到之前的结果集中
Statement stmt = conn.createStatement();
Statement stmt1 = conn.createStatement();
String sql = "select * from topic order by Producedtime DESC";
ResultSet rs = stmt.executeQuery(sql);
List list = new ArrayList();
while (rs.next()) {
topic_index = rs.getInt("topic_index");
Topic topic = new Topic();
topic.setTopic_index(topic_index);
String sql1="select * from news where news_id="+topic_index;
ResultSet rs1 = stmt.executeQuery(sql1);
String news_content=rs1.getString("news_content");
topic.setTopic_news_content(news_content);
list.add(topic);
}
request.setAttribute("list", list);
rs.close();
stmt.close();
conn.close();