表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中没有任何记录
1条答案
按热度按时间gywdnpxw1#
如果表中没有行
group by
子句存在,则max()
函数返回包含值的单行null
.