即使结果集rs.next()的rs在第二个表b中没有记录,它们的可变性如何为真



表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 中没有任何记录

max(ecode)

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

最新更新