[英]Issue with return the boolean value
在Java中使用RESTful Web服务时。 我无法返回布尔值。 在此代码中,im检查重复项。 如果存在重复,则应该退出循环。 如果不是,则应进一步进行插入。 在这种情况下,我的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
在addCategory(ParentEntity.java:157)处仔细检查代码。 如果您使用任何finally块,也请检查一下。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.