为什么我在返回TRUE / FALSE时输入错误来输入布尔值?

时间:2010-03-31 22:20:21

标签: java types boolean

我写了以下代码:

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;}

Connection类来自我创建的数据库包。

返回TRUE / FALSE是否正确,因为该函数是布尔返回类型?

2 个答案:

答案 0 :(得分:6)

在Java中,TRUE和FALSE只是标识符;可能的布尔值拼写为truefalse。还有Boolean.TRUEBoolean.FALSE,它们是Boolean包装类的相应实例。

答案 1 :(得分:4)

您可以将其简化为:

return count > 0;