问题返回布尔值

时间:2013-01-21 05:01:36

标签: java nullpointerexception

在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
ResultSetcom.mysql.jdbc.JDBC4ResultSet@1c1eceb
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

1 个答案:

答案 0 :(得分:1)

仔细检查addCategory处的代码(ParentEntity.java:157)。如果您正在使用任何finally块,请检查它。