java—结果集rs.next()的rs varaiable是真的,即使它们在第二个表b中没有记录

zvms9eto  于 2021-06-15  发布在  Mysql
关注(0)|答案(1)|浏览(300)

表a

roll
101

表b enter code here 空集

//code of java netbeans 

//table a 

    public void t1()
    {

         try
    {

        String s1 = "select max(roll) as 'rn' from a;";
        rs=stmt.executeQuery(s1);

         if(rs.next())
        {
        rn = rs.getInt("rn");
        jTextField1.setText(rn+"");
        }

    }catch(Exception e)
    {}

//table b

    public void t2()
    {
    try
    {

        String s2 = "select max(ecode)+1 as 'ec' from b;";
        rs=stmt.executeQuery(s2);
        if(rs.next())
        {

        en = rs.getInt("ec");

        }
        else
        {

         en = 2001;
        }

        jTextField2.setText(en+"");
    }catch(Exception e)
    {
    }
    }

为什么执行t2方法中的if语句,尽管表b中没有任何记录

gywdnpxw

gywdnpxw1#

max(ecode)

如果表中没有行 group by 子句存在,则 max() 函数返回包含值的单行 null .

相关问题