0

在 Java 中使用 RESTful Web 服务时。我无法返回布尔值。在此代码中,我正在检查重复项。如果存在重复,它应该脱离循环。如果不是,它应该进一步进行插入。在这种情况下,我的 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
4

1 回答 1

1

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

于 2013-01-21T06:23:36.680 回答