我有以下代码,我没有得到的是为什么我需要将deleteStatus初始化为false。如果为false,我知道默认值。
以下是方法定义。我想在这里返回一个布尔值。但是我无法理解为什么我们需要初始化它?
public boolean delete(xyzObject selObject) {
ResultSet rs = null;
PreparedStatement stmt = null;
Connection conn = null;
boolean deleteStatus ;
try{
logger.debug(" : Deleting data from the database.");
conn = db.getConnection();
stmt = conn.prepareStatement(QUERY_DELETE_XYZ);
stmt.setString(1, selObject.getxyz());
stmt.setString(1, selObject.getabc());
int update = stmt.executeUpdate();
if(update > 0 ){
logger.debug(" : Deleted xyz:" +selObject.getxyz() + " and xyz:" + selObject.getxyz());
deleteStatus = true;
}else {
logger.debug(" : Failed to delete xyz:" +selObject.getxyz() + " and xyz:" + selObject.getxyz());
}
}catch (Exception ex) {
logger.error(ex.getMessage(), ex);
} finally {
if (rs != null) {
try {
rs.close();
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
rs = null;
}
if (stmt != null) {
try {
stmt.close();
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
stmt = null;
}
if (conn != null) {
try {
conn.close();
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
conn = null;
}
}
return deleteStatus;
}