phill
phill

Reputation: 13864

Why am I getting an error when return TRUE/FALSE to type Boolean?

I wrote the following code:

import java.lang.*; 
import DB.*; 

    private Boolean validateInvoice(String i)
    {
     int count = 0;
     try
     { 
      //check how many rowsets
            ResultSet c = connection.DBquery("select count(*) from Invce i,cust c where tranid like '"+i+"' and i.key = c.key "); 
      while (c.next())
            {
             System.out.println("rowcount : " + c.getInt(1));
       count = c.getInt(1);
            } 
       if (count > 0 ) {
        return TRUE;
       } else { 
        return FALSE;
       } //end if   

     }
     catch(Exception e){e.printStackTrace();return FALSE;}
    }


    The errors I'm getting are:
    i.java:195:  cannot find symbol
    symbol : variable TRUE
    location: class changei.iTable 
                             return TRUE; 

    i.java:197:  cannot find symbol
    symbol : variable TRUE
    location: class changei.iTable 
                             return FALSE; 
i.java:201:: cannot find symbol
symbol  : variable FALSE
location: class changei.iTable 
        catch(Exception e){e.printStackTrace();return FALSE;}

The Connection class comes from the DB package i created.

Is the return TRUE/FALSE correct since the function is a Boolean return type?

Upvotes: 0

Views: 6665

Answers (2)

Roman
Roman

Reputation: 66226

You can simplify it to:

return count > 0;

Upvotes: 4

David Winslow
David Winslow

Reputation: 8590

In Java TRUE and FALSE are just identifiers; the possible boolean values are spelled true and false. There are also Boolean.TRUE and Boolean.FALSE which are corresponding instances of the Boolean wrapper class.

Upvotes: 6

Related Questions