0

table a

roll
101

table b

enter code hereempty set

//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)
    {
    }
    }

why if statement in t2 method is executed although we do not have any record in table b

Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
Anurag Rao
  • 107
  • 2

1 Answers1

0
max(ecode)

If there are no rows in the table and no group by clause is present, the max() function returns a single row containing the value null.

Jim Garrison
  • 85,615
  • 20
  • 155
  • 190