0

I have the following code what I am not getting here is why I need to initialize deleteStatus to false. I know default value if false.

Below is the method definition. I am trying to return a boolean here. But I am unable to understand why we need to initialize it?

 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;
    }

0 Answers0