如果查询结果为空,我想移至另一帧。如何检查查询是否为空?
String query2 ="Select* from biletbilgileri where Filminİsmi='" + filmKoltuk + "'" +
" " + "and" + " " + "SeansTarihi='" + SeansTarihKoltuk + "'" + " " + "and" + " " +
"SeansSaati='" + SeansSaatKoltuk + "'";
Statement stmt1=conn.createStatement();
ResultSet rs1=stmt1.executeQuery(query2);
rs1.next();
if(rs1==null)
{
tesekkurEkrani1.setVisible(true);
tesekkurEkrani1.setSize(1000,500); }
else {
JOptionPane.showMessageDialog(null, "This chair isn't empty!");
}
答案 0 :(得分:0)
您要在查询select count(*) from biletbilgileri ...
中使用SQL count(*)
。如果返回值为0,则原始查询不会返回任何行。
String query2 = "select count(*) from biletbilgileri ...";
ResultSet rs1 = stmt1.executeQuery(query2);
rs1.next();
int count = rs1.getInt(1);
if (count == 0) {
// empty
}
答案 1 :(得分:0)
当您调用rs1.next();时,它将返回一个布尔值。如果布尔值为假,则意味着不再有行。所以我认为您想这样做:
boolean notEmpty = rs1.next();
if(notEmpty )
{