2013-01-21 99 views
0

在Java中使用RESTful webservice時。我不能夠返回布爾值。在這個代碼即時檢查重複。如果有重複存在,它應該出現循環。如果不是,它應該進一步繼續插入。在這種情況下,我的ELSE部分工作正常。但是IF循環不能顯示錯誤這是我的一段代碼。問題與返回布爾值

代碼

public Boolean addCategory(String catname,String parentid)throws Exception { 
      PreparedStatement pst = null; 
      boolean resultdata = false; 
      boolean resultdata1 = false; 
      ResultSet rst=null; 
      Statement st = null; 
      int flag = 0; 
      String sql,sql1 = null; 
      try { 
       con = getConnection(); 
       st = con.createStatement(); 
       sql1="select * from xxx where parent_id='"+parentid+"' and category_description='"+catname+"'"; 
        System.out.println("Checks for Duplicate Catgory"); 
        rst = st.executeQuery(sql1); 
        System.out.println("ResultSet"+rst); 
         if(rst!=null&&rst.next()){ 
         String catname1=(String) rst.getObject("category_description"); 
         System.out.println("Category description : "+catname1); 
         System.out.println("Duplicate value is trying to get inserted"); 
         return resultdata1; 
        } 
else{ 

/** Is working fine 
} 

控制檯錯誤報告

Database connection --> 
Database established 
Checks for Duplicate Catgory 
[email protected] 
Category description : Test3 
Duplicate value is trying to get inserted 
Jan 21, 2013 10:23:23 AM com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException 
SEVERE: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container 
java.lang.NullPointerException 
+0

在重新讀取控制檯錯誤報告時,* sop「重複值試圖插入」後發生錯誤*,因此問題可能不在於這部分代碼。 –

+0

是@UsmanSaleem。如果重複存在,我想返回到方法。我測試過重複值。它經歷循環和條件測試。一切都很好,但它不返回值 –

+1

根據您的輸出控制檯,它返回值。仔細檢查你是否有一個finally塊。如前所述,您的堆棧跟蹤提到發生錯誤的代碼行。現在您已將其刪除,任何人都無法確定任何有用的東西。 –

回答

1

仔細檢查在addCategory(ParentEntity.java:157)的代碼。如果你正在使用任何finally塊,請檢查。