如果查询结果为空,我想移到另一帧。如何检查查询是否为空?

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!");
                        }

最佳答案

您要在查询count(*)中使用SQL select count(*) from biletbilgileri ...。如果返回值为0,则原始查询不返回任何行。

String query2 = "select count(*) from biletbilgileri ...";
ResultSet rs1 = stmt1.executeQuery(query2);
rs1.next();
int count = rs1.getInt(1);
if (count == 0) {
  // empty
}

09-27 17:55