首頁 >資料庫 >mysql教程 >java-第二个sql语句得到的resultset对象是空的怎么办

java-第二个sql语句得到的resultset对象是空的怎么办

WBOY
WBOY原創
2016-06-06 09:34:561719瀏覽

java数据库mysql计算机jsp

public ListgetAll1(String name) throws Exception {

Listresult = new ArrayList();

Connection con = DatabaseConnection.getConnection();

String na=null;

String sql1= "select * from guanzhu where guanzhu=?";

PreparedStatement ps1 = con.prepareStatement(sql1);

ps1.setString(1, name);

ResultSet rs1 = ps1.executeQuery();

while(rs1.next()){

Connection con1 = DatabaseConnection.getConnection();

na=rs1.getString("beiguanzhu");

String sql = "select * from message where author=? order by modified desc"; PreparedStatement ps = con1.prepareStatement(sql);

ps.setString(1, na); ResultSet rs = ps.executeQuery();

while (rs.next()) {

Message m = new Message();

m.setId(rs.getInt("id"));

m.setTitle(rs.getString("title"));

m.setContent(rs.getString("content"));

m.setModified(rs.getDate("modified"));

m.setAuthor(rs.getString("author"));

result.add(m);

System.out.println(rs.getString("author")+"");

}

}

return result;
}

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn