    @Override
    public void updateEmployee(int updateId, Employee employee) throws EmployeeException {
        Transaction transaction = null;
        try (Session session = SessionProvider.getSessionFactory().openSession()) {
            transaction = session.beginTransaction();
            session.update(employee);
            transaction.commit();
        } catch (Exception e) {
            if (transaction != null) {
                transaction.rollback();
            }
            throw new EmployeeException("Error while updating employee: " + employee.getId(), e);
        }
    }

    @Override
    public void updateEmployee(int updateId, Employee employee) throws EmployeeException {
        Session session = null;
        Transaction transaction = null;
        try {
            session = SessionProvider.getSessionFactory().openSession();
            transaction = session.beginTransaction();
            session.update(employee);
            transaction.commit();
        } catch (Exception e) {
            if (transaction != null) {
                transaction.rollback();
            }
            throw new EmployeeException("Error while updating employee: " + employee.getId(), e);
        } finally {
            if (session != null) {
                session.close();
            }
        }
    }

Try With Resources try(Session session=SessionProvider.getSessionFactory().openSession()) in method public updateEmployee(updateId int, employee Employee) : void from class com.i2i.employeemanagement.employee.dao.EmployeeDaoImpl


    @Override
    public void assignCourseToEmployee(int employeeId, int courseId) throws EmployeeException {
        Transaction transaction = null;
        try (Session session = SessionProvider.getSessionFactory().openSession()) {
            transaction = session.beginTransaction();
            Employee employee = session.get(Employee.class, employeeId);
            Course course = session.get(Course.class, courseId);
            Set<Course> courses = employee.getCourses();
            if (courses == null) {
                courses = new HashSet<>();
            }
            courses.add(course);
            employee.setCourses(courses);
            session.update(employee);
            transaction.commit();

        } catch (Exception e) {
            if (transaction != null) {
                transaction.rollback();
            }
            throw new EmployeeException("Error assigning course to employee with Id: " + employeeId, e);
        }
    }

    @Override
    public void assignCourseToEmployee(int employeeId, int courseId) throws EmployeeException {
        Session session = null;
        Transaction transaction = null;
        try {
            session = SessionProvider.getSessionFactory().openSession();
            transaction = session.beginTransaction();
            Employee employee = session.get(Employee.class, employeeId);
            Course course = session.get(Course.class, courseId);
            Set<Course> courses = employee.getCourses();
            if (courses == null) {
                courses = new HashSet<>();
            }
            courses.add(course);
            employee.setCourses(courses);
            session.update(employee);
            transaction.commit();

        } catch (Exception e) {
            if (transaction != null) {
                transaction.rollback();
            }
            throw new EmployeeException("Error assigning course to employee with Id: " + employeeId, e);
        } finally {
            if (session != null) {
                session.close();
            }
        }
    }

Try With Resources try(Session session=SessionProvider.getSessionFactory().openSession()) in method public assignCourseToEmployee(employeeId int, courseId int) : void from class com.i2i.employeemanagement.employee.dao.EmployeeDaoImpl


    @Override
    public Laptop getLaptopById(int laptopId) throws EmployeeException {
        try (Session session = SessionProvider.getSessionFactory().openSession()) {
            return session.get(Laptop.class, laptopId);
        } catch (Exception e) {
            throw new EmployeeException("Error retrieving a laptops:", e);
        }
    }

    @Override
    public Laptop getLaptopById(int laptopId) throws EmployeeException {
        Session session = null;
        try {
            session = SessionProvider.getSessionFactory().openSession();
            Laptop laptop1 = session.get(Laptop.class, laptopId);
            return laptop1;
        } catch (Exception e) {
            throw new EmployeeException("Error retrieving a laptops:", e);
        } finally {
            if (session != null) {
                session.close();
            }
        }
    }

Try With Resources try(Session session=SessionProvider.getSessionFactory().openSession()) in method public getLaptopById(laptopId int) : Laptop from class com.i2i.employeemanagement.laptop.dao.LaptopDaoImpl


    @Override
    public void updateLaptop(int laptopId, Laptop laptop) throws EmployeeException {
        Transaction transaction = null;
        try (Session session = SessionProvider.getSessionFactory().openSession()) {
            transaction = session.beginTransaction();
            session.update(laptop);
            transaction.commit();
        } catch (Exception e) {
            if (transaction != null) {
                transaction.rollback();
            }
            throw new EmployeeException("Error updating the laptopId: " + laptopId, e);
        }
    }

    @Override
    public void updateLaptop(int laptopId, Laptop laptop) throws EmployeeException {
        Session session = null;
        Transaction transaction = null;
        try {
            session = SessionProvider.getSessionFactory().openSession();
            transaction = session.beginTransaction();
            session.update(laptop);
            transaction.commit();
        } catch (Exception e) {
            if (transaction != null) {
                transaction.rollback();
            }
            throw new EmployeeException("Error updating the laptopId: " + laptopId, e);
        } finally {
            if (session != null) {
                session.close();
            }
        }
    }

Try With Resources try(Session session=SessionProvider.getSessionFactory().openSession()) in method public updateLaptop(laptopId int, laptop Laptop) : void from class com.i2i.employeemanagement.laptop.dao.LaptopDaoImpl


    @Override
    public Map<Integer, Employee> getEmployeeByLaptop(int laptopId) throws EmployeeException {
        Map<Integer, Employee> employeeDetails = new HashMap<>();
        try (Session session = SessionProvider.getSessionFactory().openSession()) {
            Laptop laptop = session.get(Laptop.class, laptopId);
            if (laptop != null && laptop.getEmployees() != null) {
                 Employee employee = laptop.getEmployees();
                 employeeDetails.put(employee.getId(), employee);
            }
        } catch (Exception e) {
            throw new EmployeeException("Error in retrieving employees by laptop " + laptopId, e);
        }
        return employeeDetails;
    }

    @Override
    public Map<Integer, Employee> getEmployeeByLaptop(int laptopId) throws EmployeeException {
        Session session = null;
        Map<Integer, Employee> employeeDetails = new HashMap<>();
        try {
            session = SessionProvider.getSessionFactory().openSession();
            Laptop laptop = session.get(Laptop.class, laptopId);
            if (laptop != null && laptop.getEmployees() != null) {
                 Employee employee = laptop.getEmployees();
                 employeeDetails.put(employee.getId(), employee);
            }
        } catch (Exception e) {
            throw new EmployeeException("Error in retrieving employees by laptop " + laptopId, e);
        } finally {
            if (session != null) {
                session.close();
            }
        }
        return employeeDetails;
    }

Try With Resources try(Session session=SessionProvider.getSessionFactory().openSession()) in method public getEmployeeByLaptop(laptopId int) : Map<Integer,Employee> from class com.i2i.employeemanagement.laptop.dao.LaptopDaoImpl


    public List<LichCapBenGa> ChonSQL(String lenhSQL, Object... thamSo) {
        List<LichCapBenGa> list = new ArrayList<>();
        try (ResultSet boKetQua = KetNoiCoSoDuLieu.truyVan(lenhSQL, thamSo)) {
            while (boKetQua.next()) {
                LichCapBenGa lich = new LichCapBenGa();
                lich.setMaLich(boKetQua.getString("MaLich"));
                lich.setGioCapBen(boKetQua.getTimestamp("GioCapBen")
                        .toInstant()
                        .atZone(ZoneId.systemDefault())
                        .toLocalDateTime());
                lich.setGioKhoiHanh(boKetQua.getTimestamp("GioKhoiHanh")
                        .toInstant()
                        .atZone(ZoneId.systemDefault())
                        .toLocalDateTime());
                lich.setMoTa(boKetQua.getString("MoTa"));
                lich.setMaGa(boKetQua.getString("MaGa"));
                lich.setMaTau(boKetQua.getString("SoHieu"));

                list.add(lich);
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
            throw new RuntimeException(ex);
        }
        return list;
    }

    public List<LichCapBenGa> ChonSQL(String lenhSQL, Object... thamSo) {
        List<LichCapBenGa> list = new ArrayList<>();
        try {
            ResultSet boKetQua = null;
            try {
                boKetQua = KetNoiCoSoDuLieu.truyVan(lenhSQL, thamSo);
                while (boKetQua.next()) {
                    LichCapBenGa lich = new LichCapBenGa();

                    list.add(lich);
                }
            } finally {
                boKetQua.getStatement().getConnection().close();
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
            throw new RuntimeException(ex);
        }

        return list;
    }

Try With Resources try(ResultSet boKetQua=KetNoiCoSoDuLieu.truyVan(lenhSQL,thamSo)) in method public ChonSQL(lenhSQL String, thamSo Object...) : List<LichCapBenGa> from class app.dao.LichCapBenGa_DAO


    public static boolean isExitReachable(Graph maze, char entrance, char exit) {
        Stack<Graph.Vertex> stack = new Stack<>();
        Graph.Vertex start = maze.getVertex(entrance);
        stack.push(start);
        while (!stack.isEmpty()) {
            Graph.Vertex current = stack.pop();
            current.setColor(VertexColor.GRAY);
            if (Character.compare((char) current.getData(), exit) == 0) return true;
            for (Object object : current.edgesIncidentFrom) {
                Graph.Edge next = (Graph.Edge) object;
                Graph.Vertex destination = next.getTo();
                if (destination.getColor().compareTo(VertexColor.GRAY) != 0) {
                    stack.push(destination);
                }
            }
        }
        return false;
    }

    public static boolean isExitReachable(Graph maze, char entrance, char exit) {
        Stack<Graph.Vertex> stack = new Stack<Graph.Vertex>();
        Graph.Vertex start = maze.getVertex(entrance);
        stack.push(start);
        while (!stack.isEmpty()) {
            Graph.Vertex current = stack.pop();
            current.setColor(VertexColor.GRAY);
            if (Character.compare((char) current.getData(), exit) == 0) return true;
            for (Object object : current.edgesIncidentFrom) {
                Graph.Edge next = (Graph.Edge) object;
                Graph.Vertex destination = next.getTo();
                if (destination.getColor().compareTo(VertexColor.GRAY) != 0) {
                    stack.push(destination);
                }
            }
        }
        return false;
    }

Replace Generic With Diamond Stack<Graph.Vertex> with Stack<> in method public isExitReachable(maze Graph, entrance char, exit char) : boolean from class cse41321.container.Homework8


    /**
     * Creates the identifier manager. Identifers are only unique if managed by the same instance.
     */
    public ModelingElementIdentifierManager() {
        elementToIdentifer = new HashMap<>();
    }

    /**
     * Creates the identifier manager. Identifers are only unique if managed by the same instance.
     */
    public ModelingElementIdentifierManager() {
        elementToIdentifer = new HashMap<EClass, Set<EObject>>();
    }

Replace Generic With Diamond HashMap<EClass,Set<EObject>> with HashMap<> in method public ModelingElementIdentifierManager() from class de.jplag.emf.util.ModelingElementIdentifierManager


    @Override
    public void writeFile(String fileContent, String folderPath, String fileName) {
        String path = Path.of(folderPath, fileName).toString();
        try (BufferedWriter writer = new BufferedWriter(new java.io.FileWriter(path))) {
            writer.write(fileContent);
        } catch (IOException e) {
            logger.error(WRITE_ERROR, e, path);
        }
    }

    @Override
    public void writeFile(String fileContent, String folderPath, String fileName) {
        String path = Path.of(folderPath, fileName).toString();
        try {
            BufferedWriter writer = new BufferedWriter(new java.io.FileWriter(path));
            writer.write(fileContent);
            writer.close();
        } catch (IOException e) {
            logger.error(WRITE_ERROR, e, path);
        }
    }

Try With Resources try(BufferedWriter writer=new BufferedWriter(new java.io.FileWriter(path))) in method public writeFile(fileContent String, folderPath String, fileName String) : void from class de.jplag.reporting.reportobject.writer.TextWriter


    private void parseFile(File file) throws ParsingException {
        try (FileInputStream fileInputStream = new FileInputStream((file))) {
            currentFile = file;

            // create a lexer that feeds off of input CharStream
            Python3Lexer lexer = new Python3Lexer(CharStreams.fromStream(fileInputStream));

            // create a buffer of tokens pulled from the lexer
            CommonTokenStream tokens = new CommonTokenStream(lexer);

            // create a parser that feeds off the tokens buffer
            Python3Parser parser = new Python3Parser(tokens);
            File_inputContext in = parser.file_input();

            ParseTreeWalker ptw = new ParseTreeWalker();
            for (int i = 0; i < in.getChildCount(); i++) {
                ParseTree pt = in.getChild(i);
                ptw.walk(new JplagPython3Listener(this), pt);
            }

        } catch (IOException e) {
            throw new ParsingException(file, e.getMessage(), e);
        }
    }

    private void parseFile(File file) throws ParsingException {
        BufferedInputStream inputStream;

        CharStream input;
        try {
            inputStream = new BufferedInputStream(new FileInputStream(file));
            currentFile = file;
            input = CharStreams.fromStream(inputStream);

            // create a lexer that feeds off of input CharStream
            Python3Lexer lexer = new Python3Lexer(input);

            // create a buffer of tokens pulled from the lexer
            CommonTokenStream tokens = new CommonTokenStream(lexer);

            // create a parser that feeds off the tokens buffer
            Python3Parser parser = new Python3Parser(tokens);
            File_inputContext in = parser.file_input();

            ParseTreeWalker ptw = new ParseTreeWalker();
            for (int i = 0; i < in.getChildCount(); i++) {
                ParseTree pt = in.getChild(i);
                ptw.walk(new JplagPython3Listener(this), pt);
            }

        } catch (IOException e) {
            throw new ParsingException(file, e.getMessage(), e);
        }
    }

Try With Resources try(FileInputStream fileInputStream=new FileInputStream((file))) in method private parseFile(file File) : void from class de.jplag.python3.Parser


    /**
     * creates the JPlag options for the test run from the values passed in the constructor.
     * @return current JPlag options for the created object
     */
    public JPlagOptions getJPlagOptionsFromCurrentModel() {
        return new JPlagOptions(new ArrayList<>(Arrays.asList(submissionFolderPath)), new ArrayList<>(), languageOption);
    }

    /**
     * creates the JPlag options for the test run from the values passed in the constructor.
     * @return current JPlag options for the created object
     */
    public JPlagOptions getJPlagOptionsFromCurrentModel() {
        return new JPlagOptions(new ArrayList<String>(Arrays.asList(submissionFolderPath)), new ArrayList<String>(), languageOption);
    }

Replace Generic With Diamond JPlagOptions with JPlagOptions in method public getJPlagOptionsFromCurrentModel() : JPlagOptions from class de.jplag.end_to_end_testing.model.TestCaseModel


    private boolean parseFile(File directory, String file) {
        InputState inputState = null;
        try (FileInputStream inputStream = new FileInputStream(new File(directory, file))) {
            currentFile = file;
            // Create a scanner that reads from the input stream passed to us
            inputState = new InputState(inputStream);
            TextLexer lexer = new TextLexer(inputState);
            lexer.setFilename(file);
            lexer.setTokenObjectClass("de.jplag.text.ParserToken");

            // Create a parser that reads from the scanner
            TextParser parser = new TextParser(lexer);
            parser.setFilename(file);
            parser.setParser(this);

            // start parsing at the compilationUnit rule
            parser.file();
        } catch (Exception e) {
            logger.error("Parsing Error in " + file + " (line " + (inputState != null ? "" + inputState.getLine() : "") + "):" + e.getMessage(), e);
            return false;
        }
        return true;
    }

    private boolean parseFile(File directory, String file) {
        InputState inputState = null;
        try {
            FileInputStream inputStream = new FileInputStream(new File(directory, file));
            currentFile = file;
            // Create a scanner that reads from the input stream passed to us
            inputState = new InputState(inputStream);
            TextLexer lexer = new TextLexer(inputState);
            lexer.setFilename(file);
            lexer.setTokenObjectClass("de.jplag.text.ParserToken");

            // Create a parser that reads from the scanner
            TextParser parser = new TextParser(lexer);
            parser.setFilename(file);
            parser.parser = this;// Added by Emeric 26.01.05 BAD

            // start parsing at the compilationUnit rule
            parser.file();

            // close file
            inputStream.close();
        } catch (Exception e) {
            logger.error("Parsing Error in '" + file + "' (line " + (inputState != null ? "" + inputState.getLine() : "") + "):\n  " + e.getMessage(),
                    e);
            return false;
        }
        return true;
    }

Try With Resources try(FileInputStream inputStream=new FileInputStream(new File(directory,file))) in method private parseFile(directory File, file String) : boolean from class de.jplag.text.Parser


    private boolean parseFile(File dir, String file) {
        char[] buffer = new char[4096];
        int type;
        int length;
        int offset = 0;

        try (FileReader reader = new FileReader(new File(dir, file), StandardCharsets.UTF_8)){
            do {
                length = reader.read(buffer);

                for (int i = 0; i < length; i++) {
                    if (buffer[i] <= 127 && (type = mapping[buffer[i]]) > 1) {
                        tokens.addToken(new CharToken(type, file, offset + i, buffer[i], this));
                    }
                }
                offset += length;
            } while (length != -1);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }

    private boolean parseFile(File dir, String file) {
        char[] buffer = new char[4096];
        int type;
        int length;
        int offset = 0;

        try {
            FileReader reader = new FileReader(new File(dir, file), StandardCharsets.UTF_8);

            do {
                length = reader.read(buffer);

                for (int i = 0; i < length; i++) {
                    if (buffer[i] <= 127 && (type = mapping[buffer[i]]) > 1) {
                        tokens.addToken(new CharToken(type, file, offset + i, buffer[i], this));
                    }
                }
                offset += length;
            } while (length != -1);

            // close file
            reader.close();
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }

Try With Resources try(FileReader reader=new FileReader(new File(dir,file),StandardCharsets.UTF_8)) in method private parseFile(dir File, file String) : boolean from class de.jplag.chars.Parser


    private boolean parseFile(File dir, String file) {
        char[] buffer = new char[4096];
        int type;
        int length;
        int offset = 0;

        try (FileReader reader = new FileReader(new File(dir, file), StandardCharsets.UTF_8)) {
            do {
                length = reader.read(buffer);

                for (int i = 0; i < length; i++) {
                    if (buffer[i] <= 127 && (type = mapping[buffer[i]]) > 1) {
                        tokens.addToken(new CharToken(type, file, offset + i, buffer[i], this));
                    }
                }
                offset += length;
            } while (length != -1);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return false;
        }
        return true;
    }


    /**
     * Responsible for calculating the {@link ClusteringResult#getCommunityStrength} of a new clustering on integers and
     * it's clusters.
     */
    public static ClusteringResult<Integer> fromIntegerCollections(List<Collection<Integer>> clustering, RealMatrix similarity) {
        int numberOfSubmissions = similarity.getRowDimension();
        Map<Integer, Integer> clusterIndicesOfSubmissionIndices = new HashMap<>();
        int clusterIdx = 0;
        for (Collection<Integer> cluster : clustering) {
            for (Integer submissionIdx : cluster) {
                clusterIndicesOfSubmissionIndices.put(submissionIdx, clusterIdx);
            }
            clusterIdx++;
        }
        List<Cluster<Integer>> clusters = new ArrayList<>(clustering.size());
        float communityStrength = 0;
        if (clustering.size() > 0) {
            RealMatrix percentagesOfSimilaritySums = new Array2DRowRealMatrix(clustering.size(), clustering.size());
            percentagesOfSimilaritySums = percentagesOfSimilaritySums.scalarMultiply(0);
            for (int i = 0; i < numberOfSubmissions; i++) {
                if (!clusterIndicesOfSubmissionIndices.containsKey(i))
                    continue;
                int clusterA = clusterIndicesOfSubmissionIndices.get(i);
                for (int j = i + 1; j < numberOfSubmissions; j++) {
                    if (!clusterIndicesOfSubmissionIndices.containsKey(j))
                        continue;
                    int clusterB = clusterIndicesOfSubmissionIndices.get(j);
                    percentagesOfSimilaritySums.addToEntry(clusterA, clusterB, similarity.getEntry(i, j));
                    percentagesOfSimilaritySums.addToEntry(clusterB, clusterA, similarity.getEntry(i, j));
                }
            }
            percentagesOfSimilaritySums = percentagesOfSimilaritySums
                    .scalarMultiply(1 / Arrays.stream(similarity.getData()).flatMapToDouble(DoubleStream::of).sum());
            for (int i = 0; i < clustering.size(); i++) {
                double outWeightSum = percentagesOfSimilaritySums.getRowVector(i).getL1Norm();
                double clusterCommunityStrength = percentagesOfSimilaritySums.getEntry(i, i) - outWeightSum * outWeightSum;
                clusters.add(new Cluster<>(clustering.get(i), (float) clusterCommunityStrength));
                communityStrength += clusterCommunityStrength;
            }
        }
        return new ClusteringResult<>(clusters, communityStrength);
    }

    /**
     * Responsible for calculating the {@link ClusteringResult#getCommunityStrength} of a new clustering on integers and
     * it's clusters.
     */
    public static ClusteringResult<Integer> fromIntegerCollections(List<Collection<Integer>> clustering, RealMatrix similarity) {
        int numberOfSubmissions = similarity.getRowDimension();
        Map<Integer, Integer> clusterIndicesOfSubmissionIndices = new HashMap<>();
        int clusterIdx = 0;
        for (Collection<Integer> cluster : clustering) {
            for (Integer submissionIdx : cluster) {
                clusterIndicesOfSubmissionIndices.put(submissionIdx, clusterIdx);
            }
            clusterIdx++;
        }
        List<Cluster<Integer>> clusters = new ArrayList<>(clustering.size());
        float communityStrength = 0;
        if (clustering.size() > 0) {
            RealMatrix percentagesOfSimilaritySums = new Array2DRowRealMatrix(clustering.size(), clustering.size());
            percentagesOfSimilaritySums = percentagesOfSimilaritySums.scalarMultiply(0);
            for (int i = 0; i < numberOfSubmissions; i++) {
                if (!clusterIndicesOfSubmissionIndices.containsKey(i))
                    continue;
                int clusterA = clusterIndicesOfSubmissionIndices.get(i);
                for (int j = i + 1; j < numberOfSubmissions; j++) {
                    if (!clusterIndicesOfSubmissionIndices.containsKey(j))
                        continue;
                    int clusterB = clusterIndicesOfSubmissionIndices.get(j);
                    percentagesOfSimilaritySums.addToEntry(clusterA, clusterB, similarity.getEntry(i, j));
                    percentagesOfSimilaritySums.addToEntry(clusterB, clusterA, similarity.getEntry(i, j));
                }
            }
            percentagesOfSimilaritySums = percentagesOfSimilaritySums
                    .scalarMultiply(1 / Arrays.stream(similarity.getData()).flatMapToDouble(DoubleStream::of).sum());
            for (int i = 0; i < clustering.size(); i++) {
                double outWeightSum = percentagesOfSimilaritySums.getRowVector(i).getL1Norm();
                double clusterCommunityStrength = percentagesOfSimilaritySums.getEntry(i, i) - outWeightSum * outWeightSum;
                clusters.add(new Cluster<Integer>(clustering.get(i), (float) clusterCommunityStrength));
                communityStrength += clusterCommunityStrength;
            }
        }
        return new ClusteringResult<>(clusters, communityStrength);
    }

Replace Generic With Diamond Cluster<Integer> with Cluster<> in method public fromIntegerCollections(clustering List<Collection<Integer>>, similarity RealMatrix) : ClusteringResult<Integer> from class de.jplag.clustering.ClusteringResult


    private static List<String> readFileLines(File file) {
        List<String> lines = new ArrayList<>();
        try (BufferedReader bufferedReader = new BufferedReader(new FileReader(file))) {
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                lines.add(line);
            }
        } catch (IOException exception) {
            System.out.println("Could not read file: " + exception.getMessage());
        }
        return lines;
    }

    private static List<String> readFileLines(File file) {
        List<String> lines = new ArrayList<>();
        try {
            BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                lines.add(line);
            }
        } catch (IOException exception) {
            System.out.println("Could not read file: " + exception.getMessage());
        }
        return lines;
    }

Try With Resources try(BufferedReader bufferedReader=new BufferedReader(new FileReader(file))) in method private readFileLines(file File) : List<String> from class de.jplag.reporting2.reportobject.ReportObjectFactory


	public static Properties loadProps(String resourceName) {
		Properties props = new Properties();
		try (InputStream in = PropertiesLoader.class.getClassLoader()
				.getResourceAsStream(resourceName);) {
			props.load(in);
			in.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return props;
	}

	public static Properties loadProps(String resourceName) {
		InputStream in = PropertiesLoader.class.getClassLoader().getResourceAsStream(resourceName);
		Properties props = new Properties();
		if (in != null) {
			try {
				props.load(in);
				in.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return props;
	}

Try With Resources try(InputStream in=PropertiesLoader.class.getClassLoader().getResourceAsStream(resourceName)) in method public loadProps(resourceName String) : Properties from class jplagUtils.PropertiesLoader


    private void doExecute() throws java.sql.SQLException, java.io.IOException {

        String sqlText = jTextAreaSQL.getSelectedText();
        if (sqlText == null || sqlText.trim().length() == 0)
            sqlText = jTextAreaSQL.getText();

        java.util.Vector data = parse(sqlText);
        try (Connection con = sqlHelper.getConnection();) {
            java.util.Iterator iter = data.iterator();
            while (iter.hasNext()) {
                String s = (String) iter.next();
                System.out.println(s);
                System.out.println();
                java.sql.Statement stmt = con.createStatement();
                int count = stmt.executeUpdate(s);
            }
            con.commit();
        }
    }

    private void doExecute() throws java.sql.SQLException, java.io.IOException {

        String sqlText = jTextAreaSQL.getSelectedText();
        if (sqlText == null || sqlText.trim().length() == 0)
            sqlText = jTextAreaSQL.getText();

        java.util.Vector data = parse(sqlText);

        java.sql.Connection con = sqlHelper.getConnection();
        try {

            java.util.Iterator iter = data.iterator();
            while (iter.hasNext()) {
                String s = (String) iter.next();
                System.out.println(s);
                System.out.println();
                java.sql.Statement stmt = con.createStatement();
                int count = stmt.executeUpdate(s);
            }

            con.commit();

        } catch (java.sql.SQLException e) {
            con.rollback();
            throw e;
        }

    }

Try With Resources try(Connection con=sqlHelper.getConnection()) in method private doExecute() : void from class au.com.totemsoft.myplanner.swing.sql.UpdateManagerApp


    private void doBackup() throws java.sql.SQLException {
        try (Connection con = sqlHelper.getConnection();) {
            /*
             * BACKUP DATABASE MyPlanner TO DISK = 'C:\BACKUP\MyPlanner_001.dat' WITH
             * FORMAT, NAME = 'Full Backup of MyPlanner' GO
             */
            con.commit();
        }
    }

    private void doBackup() throws java.sql.SQLException {

        java.sql.Connection con = sqlHelper.getConnection();
        try {
            /*
             * BACKUP DATABASE MyPlanner TO DISK = 'C:\BACKUP\MyPlanner_001.dat' WITH
             * FORMAT, NAME = 'Full Backup of MyPlanner' GO
             */
            con.commit();

        } catch (java.sql.SQLException e) {
            con.rollback();
            throw e;
        }

    }

Try With Resources try(Connection con=sqlHelper.getConnection()) in method private doBackup() : void from class au.com.totemsoft.myplanner.swing.sql.UpdateManagerApp


    protected void createDBSchema(Connection con, String dbLocation, final String dbName)
        throws IOException, SQLException
    {
        String createScript = "data/updates/core/0.sql";
        List list = parse(createScript);
        // add to Map, send to execute
        try (Statement stmt = con.createStatement();) {
            for (int i = 0; i < list.size(); i++) {
                String sql = (String) list.get(i);
                //System.out.println(sql);
                sql = sql.replaceAll("\\$\\{DB_NAME\\}", dbName);
                //sql = sql.replaceAll("(\\$\\{DB_LOCATION\\})", dbLocation);
                int idx;
                while ((idx = sql.indexOf("${DB_LOCATION}")) >= 0)
                    sql = sql.substring(0, idx) + dbLocation + sql.substring(idx + "${DB_LOCATION}".length());
                //System.out.println('\t' + sql);
                int count = stmt.executeUpdate(sql);
            }
            con.commit();
        } catch (SQLException e) {
            System.err.println(e.getMessage());
            con.rollback();
            throw e;
        } catch (RuntimeException e) {
            System.err.println(e.getMessage());
            con.rollback();
            throw e;
        }
        System.out.println("\tDB create successfully completed: " + createScript);
    }

    protected void createDBSchema(Connection con, String dbLocation, final String dbName)
        throws IOException, SQLException
    {
        String createScript = "data/updates/core/0.sql";
        List list = parse(createScript);
        // add to Map, send to execute
        try {
            Statement stmt = con.createStatement();
            for (int i = 0; i < list.size(); i++) {
                String sql = (String) list.get(i);
                //System.out.println(sql);
                sql = sql.replaceAll("\\$\\{DB_NAME\\}", dbName);
                //sql = sql.replaceAll("(\\$\\{DB_LOCATION\\})", dbLocation);
                int idx;
                while ((idx = sql.indexOf("${DB_LOCATION}")) >= 0)
                    sql = sql.substring(0, idx) + dbLocation + sql.substring(idx + "${DB_LOCATION}".length());
                //System.out.println('\t' + sql);
                int count = stmt.executeUpdate(sql);
            }
            stmt.close();
            con.commit();
        } catch (SQLException e) {
            System.err.println(e.getMessage());
            con.rollback();
            throw e;
        } catch (RuntimeException e) {
            System.err.println(e.getMessage());
            con.rollback();
            throw e;
        }
        System.out.println("\tDB create successfully completed: " + createScript);
    }

Try With Resources try(Statement stmt=con.createStatement()) in method protected createDBSchema(con Connection, dbLocation String, dbName String) : void from class au.com.totemsoft.myplanner.dao.hibernate.AbstractSQLHelper


    /**
     *
     */
    public Business load(Integer businessId) throws SQLException, ObjectNotFoundException {
        String sql = "SELECT b.*" + " FROM Business b WHERE (b.BusinessID=?)";
        try (Connection con = sqlHelper.getConnection();
                PreparedStatement pstmt = con.prepareStatement(sql);) {
            pstmt.setInt(1, businessId);
            ResultSet rs = pstmt.executeQuery();
            if (!rs.next()) {
                throw new ObjectNotFoundException("Can not find Business ID: " + businessId);
            }
            //
            Business result = new Business();
            result.setId(businessId);
            result.setParentId((Integer) rs.getObject("ParentBusinessID"));
            result.setIndustryCodeID((Integer) rs.getObject("IndustryCodeID"));
            result.setBusinessStructureCodeID((Integer) rs.getObject("BusinessStructureCodeID"));
            result.setLegalName(rs.getString("LegalName"));
            result.setTradingName(rs.getString("TradingName"));
            result.setBusinessNumber(rs.getString("BusinessNumber"));
            result.setTaxFileNumber(rs.getString("TaxFileNumber"));
            result.setWebSiteName(rs.getString("WebSiteName"));
            result.setDateCreated(rs.getDate("DateCreated"));
            result.setDateModified(rs.getDate("DateModified"));
            rs.close();
            //
            return result;
        }
    }

    /**
     *
     */
    public Business load(Integer businessId) throws SQLException, ObjectNotFoundException {
        Connection con = null;
        PreparedStatement sql = null;
        ResultSet rs = null;
        try {
            con = sqlHelper.getConnection();
            sql = con.prepareStatement("SELECT b.*" + " FROM Business b"
                    + " WHERE (b.BusinessID=?)", ResultSet.TYPE_FORWARD_ONLY,
                    ResultSet.CONCUR_READ_ONLY);
            sql.setInt(1, businessId);
            rs = sql.executeQuery();
            if (!rs.next()) {
                throw new ObjectNotFoundException("Can not find Business ID: " + businessId);
            }
            //
            Business result = new Business();
            result.setId(businessId);
            result.setParentId((Integer) rs.getObject("ParentBusinessID"));
            result.setIndustryCodeID((Integer) rs.getObject("IndustryCodeID"));
            result.setBusinessStructureCodeID((Integer) rs.getObject("BusinessStructureCodeID"));
            result.setLegalName(rs.getString("LegalName"));
            result.setTradingName(rs.getString("TradingName"));
            result.setBusinessNumber(rs.getString("BusinessNumber"));
            result.setTaxFileNumber(rs.getString("TaxFileNumber"));
            result.setWebSiteName(rs.getString("WebSiteName"));
            result.setDateCreated(rs.getDate("DateCreated"));
            result.setDateModified(rs.getDate("DateModified"));
            //
            return result;
        } finally {
            sqlHelper.close(rs, sql);
            con.close();
        }
    }

Try With Resources try(Connection con=sqlHelper.getConnection(); PreparedStatement pstmt=con.prepareStatement(sql)) in method public load(businessId Integer) : Business from class au.com.totemsoft.myplanner.dao.hibernate.BusinessDaoImpl


    public Integer find(IBusiness business) throws SQLException {
        String sql = "SELECT BusinessID"
            + " FROM Business" + " WHERE" + " ( LegalName = ? )"
            + " OR ( TradingName = ? )" + " OR ( BusinessNumber = ? )"
            + " OR ( TaxFileNumber = ? )";
        try (Connection con = sqlHelper.getConnection();
                PreparedStatement pstmt = con.prepareStatement(sql);) {
            int i = 0;
            pstmt.setString(++i, business.getLegalName());
            pstmt.setString(++i, business.getTradingName());
            pstmt.setString(++i, business.getBusinessNumber());
            pstmt.setString(++i, business.getTaxFileNumber());
            try (ResultSet rs = pstmt.executeQuery();) {
                if (rs.next()) {
                    return (Integer) rs.getObject(1);
                }
                return null;
            }
        }
    }

    public Integer find(IBusiness business) throws SQLException {
        Connection con = null;
        PreparedStatement sql = null;
        ResultSet rs = null;
        try {
            con = sqlHelper.getConnection();
            sql = con.prepareStatement("SELECT BusinessID"
                + " FROM Business" + " WHERE" + " ( LegalName = ? )"
                + " OR ( TradingName = ? )" + " OR ( BusinessNumber = ? )"
                + " OR ( TaxFileNumber = ? )", ResultSet.TYPE_FORWARD_ONLY,
                ResultSet.CONCUR_READ_ONLY);
            int i = 0;
            sql.setString(++i, business.getLegalName());
            sql.setString(++i, business.getTradingName());
            sql.setString(++i, business.getBusinessNumber());
            sql.setString(++i, business.getTaxFileNumber());
            rs = sql.executeQuery();
            if (rs.next()) {
                return (Integer) rs.getObject(1);
            }
            return null;
        } finally {
            sqlHelper.close(rs, sql);
            con.close();
        }
    }

Try With Resources try(Connection con=sqlHelper.getConnection(); PreparedStatement pstmt=con.prepareStatement(sql)) in method public find(business IBusiness) : Integer from class au.com.totemsoft.myplanner.dao.hibernate.BusinessDaoImpl


    public List getLinkedObjects(int ownerPrimaryKeyID,
            int linkObjectTypeID, // first level linkage
            boolean toObjectID1, Connection con) throws SQLException {
        String sql = toObjectID1 ? "SELECT ObjectID2"
            + " FROM Link"
            + " WHERE ( ObjectID1=? ) AND ( LinkObjectTypeID=? )"
            + " AND ( LogicallyDeleted IS NULL )" : "SELECT ObjectID1"
            + " FROM Link"
            + " WHERE ( ObjectID2=? ) AND ( LinkObjectTypeID=? )"
            + " AND ( LogicallyDeleted IS NULL )";
        try (PreparedStatement pstm = con.prepareStatement(sql);) {
            pstm.setInt(1, ownerPrimaryKeyID);
            pstm.setInt(2, linkObjectTypeID);
            ResultSet rs = pstm.executeQuery();
            List list = null;
            while (rs.next()) {
                if (list == null)
                    list = new ArrayList();
                list.add(rs.getObject(toObjectID1 ? "ObjectID2" : "ObjectID1"));
            }
            rs.close();
            return list;
        }
    }

    public List getLinkedObjects(int ownerPrimaryKeyID,
            int linkObjectTypeID, // first level linkage
            boolean toObjectID1, Connection con) throws SQLException {

        List list = null;

        PreparedStatement sql = null;
        ResultSet rs = null;

        try {
            sql = con.prepareStatement(toObjectID1 ? "SELECT ObjectID2"
                    + " FROM Link"
                    + " WHERE ( ObjectID1=? ) AND ( LinkObjectTypeID=? )"
                    + " AND ( LogicallyDeleted IS NULL )" : "SELECT ObjectID1"
                    + " FROM Link"
                    + " WHERE ( ObjectID2=? ) AND ( LinkObjectTypeID=? )"
                    + " AND ( LogicallyDeleted IS NULL )",
                    ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);

            sql.setInt(1, ownerPrimaryKeyID);
            sql.setInt(2, linkObjectTypeID);
            rs = sql.executeQuery();

            while (rs.next()) {
                if (list == null)
                    list = new ArrayList();
                list.add(rs.getObject(toObjectID1 ? "ObjectID2" : "ObjectID1"));
            }

            return list;

        } finally {
            sqlHelper.close(rs, sql);
        }

    }

Try With Resources try(PreparedStatement pstm=con.prepareStatement(sql)) in method public getLinkedObjects(ownerPrimaryKeyID int, linkObjectTypeID int, toObjectID1 boolean, con Connection) : List from class au.com.totemsoft.myplanner.dao.hibernate.LinkObjectDaoImpl


    public List getLinkedObjects(
            int ownerPrimaryKeyID, int linkObjectTypeID1, // first level
                                                            // linkage
            int objectID2, int linkObjectTypeID2, boolean toObjectID1, // second
                                                                        // level
                                                                        // linkage
            Connection con) throws SQLException {
        String sql = toObjectID1 ? "SELECT ObjectID2"
            + " FROM Link"
            + " WHERE ( ObjectID1 = ? ) AND ( LinkObjectTypeID = ? )"
            + " AND ( LinkID IN"
            + " (SELECT ObjectID1"
            + " FROM Link"
            + " WHERE"
            + (objectID2 <= 0 ? " ( ObjectID2 IS NULL )" : " ( ObjectID2 = ? )")
            + " AND ( LinkObjectTypeID = ? )"
            + " AND ( LogicallyDeleted IS NULL )"
            + " )"
            + " AND ( LogicallyDeleted IS NULL )"
            + " )"
            : "SELECT ObjectID1"
                + " FROM Link"
                + " WHERE ( ObjectID2 = ? ) AND ( LinkObjectTypeID = ? )"
                + " AND ( LinkID IN"
                + " (SELECT ObjectID2"
                + " FROM Link"
                + " WHERE"
                + (objectID2 <= 0 ? " ( ObjectID1 IS NULL )" : " ( ObjectID1 = ? )")
                + " AND ( LinkObjectTypeID = ? )"
                + " AND ( LogicallyDeleted IS NULL )"
                + " )"
                + " AND ( LogicallyDeleted IS NULL )"
                + " )";
        try (PreparedStatement pstm = con.prepareStatement(sql);) {
            int i = 0;
            pstm.setInt(++i, ownerPrimaryKeyID);
            pstm.setInt(++i, linkObjectTypeID1);
            if (objectID2 > 0)
                pstm.setInt(++i, objectID2);
            pstm.setInt(++i, linkObjectTypeID2);
            ResultSet rs = pstm.executeQuery();
            ArrayList list = null;
            while (rs.next()) {
                if (list == null)
                    list = new ArrayList();
                list.add(rs.getObject(toObjectID1 ? "ObjectID2" : "ObjectID1"));
            }
            rs.close();
            return list;
        }
    }

    public List getLinkedObjects(
            int ownerPrimaryKeyID, int linkObjectTypeID1, // first level
                                                            // linkage
            int objectID2, int linkObjectTypeID2, boolean toObjectID1, // second
                                                                        // level
                                                                        // linkage
            Connection con) throws SQLException {

        ArrayList list = null;

        PreparedStatement sql = null;
        ResultSet rs = null;

        try {
            sql = con
                    .prepareStatement(
                            toObjectID1 ? "SELECT ObjectID2"
                                    + " FROM Link"
                                    + " WHERE ( ObjectID1 = ? ) AND ( LinkObjectTypeID = ? )"
                                    + " AND ( LinkID IN"
                                    + " (SELECT ObjectID1"
                                    + " FROM Link"
                                    + " WHERE"
                                    + (objectID2 <= 0 ? " ( ObjectID2 IS NULL )"
                                            : " ( ObjectID2 = ? )")
                                    + " AND ( LinkObjectTypeID = ? )"
                                    + " AND ( LogicallyDeleted IS NULL )"
                                    + " )"
                                    + " AND ( LogicallyDeleted IS NULL )"
                                    + " )"
                                    : "SELECT ObjectID1"
                                            + " FROM Link"
                                            + " WHERE ( ObjectID2 = ? ) AND ( LinkObjectTypeID = ? )"
                                            + " AND ( LinkID IN"
                                            + " (SELECT ObjectID2"
                                            + " FROM Link"
                                            + " WHERE"
                                            + (objectID2 <= 0 ? " ( ObjectID1 IS NULL )"
                                                    : " ( ObjectID1 = ? )")
                                            + " AND ( LinkObjectTypeID = ? )"
                                            + " AND ( LogicallyDeleted IS NULL )"
                                            + " )"
                                            + " AND ( LogicallyDeleted IS NULL )"
                                            + " )",
                            ResultSet.TYPE_FORWARD_ONLY,
                            ResultSet.CONCUR_READ_ONLY);

            int i = 0;
            sql.setInt(++i, ownerPrimaryKeyID);
            sql.setInt(++i, linkObjectTypeID1);
            if (objectID2 > 0)
                sql.setInt(++i, objectID2);
            sql.setInt(++i, linkObjectTypeID2);
            rs = sql.executeQuery();

            while (rs.next()) {
                if (list == null)
                    list = new ArrayList();
                list.add(rs.getObject(toObjectID1 ? "ObjectID2" : "ObjectID1"));
            }
            return list;

        } finally {
            sqlHelper.close(rs, sql);
        }

    }

Try With Resources try(PreparedStatement pstm=con.prepareStatement(sql)) in method public getLinkedObjects(ownerPrimaryKeyID int, linkObjectTypeID1 int, objectID2 int, linkObjectTypeID2 int, toObjectID1 boolean, con Connection) : List from class au.com.totemsoft.myplanner.dao.hibernate.LinkObjectDaoImpl


    @Override
    public Financial findFinancial(Integer personId, Integer financialId) {
        try (Connection con = sqlHelper.getConnection();) {
            Integer objectTypeId = null;
            String sql = "SELECT ObjectTypeID FROM Object WHERE ObjectID = ?";
            try (PreparedStatement pstm = con.prepareStatement(sql);) {
                int i = 0;
                pstm.setInt(++i, financialId);
                try (ResultSet rs = pstm.executeQuery();) {
                    // save id, typeId ONLY
                    if (!rs.next()) {
                        return null;
                    }
                    objectTypeId = rs.getInt("ObjectTypeID");
                }
            }
            FinancialBean fb = ObjectClass.createNewInstance(objectTypeId);
            return initFinancial(financialId, personId, fb, con);
        } catch (SQLException e) {
            sqlHelper.printSQLException(e);
            throw new ServiceException(e.getMessage());
        }
    }

    @Override
    public Financial findFinancial(Integer personId, Integer financialId) {
        try (Connection con = sqlHelper.getConnection();) {
            PreparedStatement sql = null;
            ResultSet rs = null;
            Integer objectTypeId = null;
            try {
                sql = con.prepareStatement(
                    "SELECT ObjectTypeID FROM Object WHERE ObjectID = ?",
                    ResultSet.TYPE_FORWARD_ONLY,
                    ResultSet.CONCUR_READ_ONLY);

                int i = 0;
                sql.setInt(++i, financialId);
                rs = sql.executeQuery();

                // save id, typeId ONLY
                if (!rs.next()) {
                    return null;
                }
                objectTypeId = rs.getInt("ObjectTypeID");
            } finally {
                sqlHelper.close(rs, sql);
            }

            FinancialBean fb = ObjectClass.createNewInstance(objectTypeId);
            return initFinancial(financialId, personId, fb, con);
        } catch (SQLException e) {
            sqlHelper.printSQLException(e);
            throw new ServiceException(e.getMessage());
        }
    }

Try With Resources try(ResultSet rs=pstm.executeQuery()) in method public findFinancial(personId Integer, financialId Integer) : Financial from class au.com.totemsoft.myplanner.service.impl.FinancialServiceImpl


    @Override
    public Map<Integer, Map<Integer, Financial>> findFinancials(Integer personId, Integer strategyGroupId) {
        try (Connection con = sqlHelper.getConnection();) {
            Map<Integer, Map<Integer, Financial>> result = null;
            // get object id's for ALL person financial
            String sql = "SELECT FinancialID, ObjectID, ObjectTypeID"
                    + " FROM Financial, Object"
                    + " WHERE"
                    + " (FinancialID IN"
                    + " (SELECT ObjectID2 FROM Link WHERE ObjectID1 = ? AND LinkObjectTypeID = ? AND LogicallyDeleted IS NULL)"
                    + " ) AND (NextID IS NULL)"
                    + (strategyGroupId == null ? " AND (StrategyGroupID IS NULL)" : " AND (StrategyGroupID = ?)")
                    + " AND (FinancialID = ObjectID)";
            try (PreparedStatement pstm = con.prepareStatement(sql);) {
                int i = 0;
                pstm.setInt(++i, personId.intValue());
                pstm.setInt(++i, LinkObjectTypeConstant.PERSON_2_FINANCIAL); // 1004
                if (strategyGroupId != null) {
                    pstm.setInt(++i, strategyGroupId.intValue());
                }
                try (ResultSet rs = pstm.executeQuery()) {
                    // save id, typeId ONLY
                    while (rs.next()) {
                        if (result == null) {
                            result = new TreeMap<Integer, Map<Integer, Financial>>(new CodeComparator<Integer>());
                        }
                        Integer id = rs.getInt("FinancialID");
                        Integer objectTypeId = rs.getInt("ObjectTypeID");
                        // get/create map for this object type
                        Map<Integer, Financial> map = result.get(objectTypeId);
                        if (map == null) {
                            // map = new TreeMap();
                            map = new TreeMap<Integer, Financial>(new CodeComparator<Integer>());
                            result.put(objectTypeId, map);
                        }
                        map.put(id, null); // load Financial object later (on request)
                    }
                    if (result == null) {
                        return null;
                    }
                }
            }
            // create ALL objects for ALL object types
            // init null Financial objects (if any) for this object type
            Iterator<Integer> iter = result.keySet().iterator();
            while (iter.hasNext()) {
                initFinancials(personId, result, iter.next(), con);
            }
            // Map( ObjectTypeID, Map( ObjectID, Object ) )
            return result;
        } catch (SQLException e) {
            sqlHelper.printSQLException(e);
            //con.rollback();
            throw new ServiceException(e.getMessage());
        }
    }

    @Override
    public Map<Integer, Map<Integer, Financial>> findFinancials(Integer personId, Integer strategyGroupId) {
        try (Connection con = sqlHelper.getConnection();) {
            PreparedStatement sql = null;
            ResultSet rs = null;
            Map<Integer, Map<Integer, Financial>> result = null;
            // get object id's for ALL person financial
            try {
                sql = con.prepareStatement(
                    "SELECT FinancialID, ObjectID, ObjectTypeID"
                    + " FROM Financial, Object"
                    + " WHERE"
                    + " (FinancialID IN"
                    + " (SELECT ObjectID2 FROM Link WHERE ObjectID1 = ? AND LinkObjectTypeID = ? AND LogicallyDeleted IS NULL)"
                    + " ) AND (NextID IS NULL)"
                    + (strategyGroupId == null ? " AND (StrategyGroupID IS NULL)" : " AND (StrategyGroupID = ?)")
                    + " AND (FinancialID = ObjectID)",
                    ResultSet.TYPE_FORWARD_ONLY,
                    ResultSet.CONCUR_READ_ONLY);

                int i = 0;
                sql.setInt(++i, personId.intValue());
                sql.setInt(++i, LinkObjectTypeConstant.PERSON_2_FINANCIAL); // 1004
                if (strategyGroupId != null) {
                    sql.setInt(++i, strategyGroupId.intValue());
                }
                rs = sql.executeQuery();

                // save id, typeId ONLY
                while (rs.next()) {
                    if (result == null) {
                        result = new TreeMap<Integer, Map<Integer, Financial>>(new CodeComparator<Integer>());
                    }
                    Integer id = rs.getInt("FinancialID");
                    Integer objectTypeId = rs.getInt("ObjectTypeID");
                    // get/create map for this object type
                    Map<Integer, Financial> map = result.get(objectTypeId);
                    if (map == null) {
                        // map = new TreeMap();
                        map = new TreeMap<Integer, Financial>(new CodeComparator<Integer>());
                        result.put(objectTypeId, map);
                    }
                    map.put(id, null); // load Financial object later (on request)
                }
                if (result == null) {
                    return null;
                }
            } finally {
                sqlHelper.close(rs, sql);
            }

            // create ALL objects for ALL object types
            // init null Financial objects (if any) for this object type
            Iterator<Integer> iter = result.keySet().iterator();
            while (iter.hasNext()) {
                initFinancials(personId, result, iter.next(), con);
            }
            // Map( ObjectTypeID, Map( ObjectID, Object ) )
            return result;
        } catch (SQLException e) {
            sqlHelper.printSQLException(e);
            //con.rollback();
            throw new ServiceException(e.getMessage());
        }
    }

Try With Resources try(ResultSet rs=pstm.executeQuery()) in method public findFinancials(personId Integer, strategyGroupId Integer) : Map<Integer,Map<Integer,Financial>> from class au.com.totemsoft.myplanner.service.impl.FinancialServiceImpl


    public List<Contact> findUsers() throws ServiceException {
        try (Connection con = sqlHelper.getConnection();) {
            Vector<Contact> data = null;
            String sql = "SELECT UserPersonID FROM UserPerson";
            try (PreparedStatement pstm = con.prepareStatement(sql);
                    ResultSet rs = pstm.executeQuery();) {
                while (rs.next()) {
                    if (data == null)
                        data = new Vector<Contact>();
                    Contact c = new Contact();
                    c.setId((Integer) rs.getObject(1)); // UserPersonID
                    data.addElement(c);
                }
            }

            if (data == null)
                return null;

            Iterator<Contact> iter = data.iterator();
            ArrayList<Contact> toRemove = new ArrayList<Contact>();
            while (iter.hasNext()) {
                Contact c = (Contact) iter.next();
                new ContactBean(c).load(con);
                if (c.toString().trim().length() == 0) {
                    //System.err.println("UserServiceImpl::findUsers(), c.toString().trim().length() == 0 for ID:" + c.getId());
                    // mark for remove
                    toRemove.add(c);
                }
            }
            iter = toRemove.iterator();
            while (iter.hasNext()) {
                Contact c = iter.next();
                data.remove(c);
            }
            return data;
        } catch (SQLException e) {
            //e.printStackTrace();
            throw new ServiceException(e);
        } catch (Exception e) {
            throw new ServiceException(e);
        }
    }

    public List<Contact> findUsers() throws ServiceException {
        Connection con = null;
        PreparedStatement sql = null;
        ResultSet rs = null;
        try {
            con = sqlHelper.getConnection();
            StringBuffer sb = new StringBuffer("SELECT UserPersonID FROM UserPerson");
            sql = con.prepareStatement(sb.toString());
            rs = sql.executeQuery();
            Vector<Contact> data = null;
            while (rs.next()) {
                if (data == null)
                    data = new Vector<Contact>();
                Contact c = new Contact();
                c.setId((Integer) rs.getObject(1)); // UserPersonID
                data.addElement(c);
            }

            sqlHelper.close(rs, sql);
            rs = null;
            sql = null;

            if (data == null)
                return null;

            Iterator<Contact> iter = data.iterator();
            ArrayList<Contact> toRemove = new ArrayList<Contact>();
            while (iter.hasNext()) {
                Contact c = (Contact) iter.next();
                new ContactBean(c).load(con);
                if (c.toString().trim().length() == 0) {
                    //System.err.println("UserServiceImpl::findUsers(), c.toString().trim().length() == 0 for ID:" + c.getId());
                    // mark for remove
                    toRemove.add(c);
                }
            }

            iter = toRemove.iterator();
            while (iter.hasNext()) {
                Contact c = iter.next();
                data.remove(c);
            }

            return data;

        } catch (SQLException e) {
            //e.printStackTrace();
            throw new ServiceException(e);
        } catch (Exception e) {
            throw new ServiceException(e);
        } finally {
            try {
                sqlHelper.close(rs, sql);
                if (con != null)
                    con.close();
            } catch (SQLException e) {
                throw new ServiceException(e);
            }
        }

    }

Try With Resources try(PreparedStatement pstm=con.prepareStatement(sql); ResultSet rs=pstm.executeQuery()) in method public findUsers() : List<Contact> from class au.com.totemsoft.myplanner.service.impl.UtilityServiceImpl


    public java.util.TreeMap getCodes(String tableName, String fieldKeyValues,
            String fieldKey) throws ServiceException {
        String sql = "SELECT " + fieldKey + ", " + fieldKeyValues + " FROM " + tableName;
        try (Connection con = sqlHelper.getConnection();
                Statement pstm = con.createStatement();
                ResultSet rs = pstm.executeQuery(sql);) {
            java.util.TreeMap map = null;
            while (rs.next()) {
                if (map == null)
                    map = new java.util.TreeMap();

                String key = rs.getString(fieldKey).trim();
                Object values = getValues(rs, fieldKeyValues);
                map.put(key, values);
            }
            return map;
        } catch (SQLException e) {
            e.printStackTrace(System.err);
            throw new ServiceException(e.getMessage());
        }
    }

    public java.util.TreeMap getCodes(String tableName, String fieldKeyValues,
            String fieldKey) throws ServiceException {

        Connection con = null;
        Statement sql = null;
        ResultSet rs = null;

        try {
            con = sqlHelper.getConnection();

            sql = con.createStatement();
            rs = sql.executeQuery("SELECT " + fieldKey + ", " + fieldKeyValues
                    + " FROM " + tableName);

            java.util.TreeMap map = null;

            while (rs.next()) {
                if (map == null)
                    map = new java.util.TreeMap();

                String key = rs.getString(fieldKey).trim();
                Object values = getValues(rs, fieldKeyValues);
                map.put(key, values);

            }

            return map;

        } catch (SQLException e) {
            e.printStackTrace(System.err);
            throw new ServiceException(e.getMessage());

        } finally {
            try {
                sqlHelper.close(rs, sql);
                if (con != null)
                    con.close();
            } catch (SQLException e) {
                throw new ServiceException(e.getMessage());
            }

        }

    }

Try With Resources try(Connection con=sqlHelper.getConnection(); Statement pstm=con.createStatement(); ResultSet rs=pstm.executeQuery(sql)) in method public getCodes(tableName String, fieldKeyValues String, fieldKey String) : TreeMap from class au.com.totemsoft.myplanner.service.impl.UtilityServiceImpl


    /**
     * Map( StateCodeID, Object [] { postCode2Suburbs = Map( PostCode,
     * List(Suburb) ), suburb2PostCodes = Map( Suburb, List(PostCode) ) } )
     */
    public java.util.Map getPostCodes(Integer countryCodeID)
            throws ServiceException {
        int stateCodeID = 0;
        String postCode = null;
        String suburb = null;
        java.util.Map map = new java.util.TreeMap();
        java.util.Map postCode2Suburbs = null;
        java.util.Map suburb2PostCodes = null;
        try (Connection con = sqlHelper.getConnection();) {
            // 1. postCode2Suburbs
            String sql = "SELECT StateCodeID, PostCode, Suburb"
                + " FROM SuburbPostCode WHERE CountryCodeID=?"
                + " ORDER BY StateCodeID, PostCode, Suburb";
            try (PreparedStatement pstm = con.prepareStatement(sql);) {
                pstm.setInt(1, countryCodeID.intValue());
                try (ResultSet rs = pstm.executeQuery();) {
                    java.util.List suburbs = null;
                    while (rs.next()) {
                        int _stateCodeID = rs.getInt(1);
                        String _postCode = rs.getString(2).trim();
                        String _suburb = rs.getString(3).trim();
                        // new state, has distinct postcodes
                        if (stateCodeID != _stateCodeID) {
                            // next state group (order by state)
                            stateCodeID = _stateCodeID;
                            postCode = _postCode;
                            postCode2Suburbs = new java.util.TreeMap();
                            postCode2Suburbs.put(Code.NONE, null);
                            suburbs = new java.util.ArrayList();
                            postCode2Suburbs.put(postCode, suburbs);
                            suburbs.add(Code.NONE);
                            map.put(new Integer(_stateCodeID), new Object[] {
                                    postCode2Suburbs, new java.util.TreeMap() });
                        } else {
                            // postCode2Suburbs = Map( PostCode, List(Suburb) ordered by postcode
                            if (!_postCode.equals(postCode)) {
                                postCode = _postCode;
                                suburbs = new java.util.ArrayList();
                                postCode2Suburbs.put(postCode, suburbs);
                                suburbs.add(Code.NONE);
                            }
                        }
                        suburbs.add(_suburb);
                    }
                }
            }

            stateCodeID = 0;

            // 2. suburb2PostCodes
            sql = "SELECT StateCodeID, Suburb, PostCode"
                    + " FROM SuburbPostCode WHERE CountryCodeID=?"
                    + " ORDER BY StateCodeID, Suburb, PostCode";
            try (PreparedStatement pstm = con.prepareStatement(sql);) {
                pstm.setInt(1, countryCodeID.intValue());
                try (ResultSet rs = pstm.executeQuery();) {
                    java.util.List postCodes = null;
                    while (rs.next()) {
                        int _stateCodeID = rs.getInt(1);
                        String _suburb = rs.getString(2).trim();
                        String _postCode = rs.getString(3).trim();
                        // new state, has distinct postcodes
                        if (stateCodeID != _stateCodeID) {
                            // next state group (order by state)
                            stateCodeID = _stateCodeID;
                            suburb = _suburb;
                            suburb2PostCodes = (java.util.TreeMap) ((Object[]) map
                                    .get(new Integer(stateCodeID)))[1];
                            suburb2PostCodes.put(Code.NONE, null);
                            postCodes = new java.util.ArrayList();
                            suburb2PostCodes.put(_suburb, postCodes);
                            postCodes.add(Code.NONE);
                        } else {
                            // suburb2PostCodes = Map( Suburb, List(PostCode) ordered by Suburb
                            if (!_suburb.equals(suburb)) {
                                suburb = _suburb;
                                postCodes = new java.util.ArrayList();
                                suburb2PostCodes.put(_suburb, postCodes);
                                postCodes.add(Code.NONE);
                            }
                        }
                        postCodes.add(_postCode);
                    }
                }
            }
            return map;
        } catch (SQLException e) {
            throw new ServiceException(e.getMessage());
        }
    }

    /**
     * Map( StateCodeID, Object [] { postCode2Suburbs = Map( PostCode,
     * List(Suburb) ), suburb2PostCodes = Map( Suburb, List(PostCode) ) } )
     */
    public java.util.Map getPostCodes(Integer countryCodeID)
            throws ServiceException {

        Connection con = null;
        PreparedStatement sql = null;
        ResultSet rs = null;

        int stateCodeID = 0;
        String postCode = null;
        String suburb = null;

        java.util.Map map = new java.util.TreeMap();

        java.util.Map postCode2Suburbs = null;
        java.util.Map suburb2PostCodes = null;

        try {
            con = sqlHelper.getConnection();

            // 1. postCode2Suburbs
            sql = con.prepareStatement("SELECT StateCodeID, PostCode, Suburb"
                    + " FROM SuburbPostCode WHERE CountryCodeID=?"
                    + " ORDER BY StateCodeID, PostCode, Suburb");
            sql.setInt(1, countryCodeID.intValue());

            rs = sql.executeQuery();

            java.util.List suburbs = null;
            while (rs.next()) {

                int _stateCodeID = rs.getInt(1);
                String _postCode = rs.getString(2).trim();
                String _suburb = rs.getString(3).trim();

                // new state, has distinct postcodes
                if (stateCodeID != _stateCodeID) {
                    // next state group (order by state)

                    stateCodeID = _stateCodeID;
                    postCode = _postCode;

                    postCode2Suburbs = new java.util.TreeMap();
                    postCode2Suburbs.put(Code.NONE, null);

                    suburbs = new java.util.ArrayList();
                    postCode2Suburbs.put(postCode, suburbs);
                    suburbs.add(Code.NONE);

                    map.put(new Integer(_stateCodeID), new Object[] {
                            postCode2Suburbs, new java.util.TreeMap() });

                } else {

                    // postCode2Suburbs = Map( PostCode, List(Suburb) ordered by
                    // postcode
                    if (!_postCode.equals(postCode)) {
                        postCode = _postCode;

                        suburbs = new java.util.ArrayList();
                        postCode2Suburbs.put(postCode, suburbs);
                        suburbs.add(Code.NONE);
                    }

                }
                suburbs.add(_suburb);

            }
            sqlHelper.close(rs, sql);

            stateCodeID = 0;

            // 2. suburb2PostCodes
            sql = con.prepareStatement("SELECT StateCodeID, Suburb, PostCode"
                    + " FROM SuburbPostCode WHERE CountryCodeID=?"
                    + " ORDER BY StateCodeID, Suburb, PostCode");
            sql.setInt(1, countryCodeID.intValue());

            rs = sql.executeQuery();

            java.util.List postCodes = null;
            while (rs.next()) {

                int _stateCodeID = rs.getInt(1);
                String _suburb = rs.getString(2).trim();
                String _postCode = rs.getString(3).trim();

                // new state, has distinct postcodes
                if (stateCodeID != _stateCodeID) {
                    // next state group (order by state)

                    stateCodeID = _stateCodeID;
                    suburb = _suburb;

                    suburb2PostCodes = (java.util.TreeMap) ((Object[]) map
                            .get(new Integer(stateCodeID)))[1];
                    suburb2PostCodes.put(Code.NONE, null);

                    postCodes = new java.util.ArrayList();
                    suburb2PostCodes.put(_suburb, postCodes);
                    postCodes.add(Code.NONE);

                } else {

                    // suburb2PostCodes = Map( Suburb, List(PostCode) ordered by
                    // Suburb
                    if (!_suburb.equals(suburb)) {
                        suburb = _suburb;

                        postCodes = new java.util.ArrayList();
                        suburb2PostCodes.put(_suburb, postCodes);
                        postCodes.add(Code.NONE);
                    }

                }
                postCodes.add(_postCode);

            }
            sqlHelper.close(rs, sql);
            con.close();

            return map;

        } catch (SQLException e) {
            throw new ServiceException(e.getMessage());
        }

    }

Try With Resources try(ResultSet rs=pstm.executeQuery()) in method public getPostCodes(countryCodeID Integer) : Map from class au.com.totemsoft.myplanner.service.impl.UtilityServiceImpl


    /**
     * CONTAINER structure Map( objType, Map( ReferenceCode( finTypeID,
     * finTypeDesc ), Vector( ReferenceCode( finCodeID, finCode, finCodeDesc ) ) ) )
     */
    public java.util.Map getFinancialObjectTypes() throws ServiceException {
        String sql = "SELECT"
            + " ft.ObjectTypeID, ft.FinancialTypeID, ft.FinancialTypeDesc,"
            + " fc.FinancialCodeID, fc.FinancialCode, fc.FinancialCodeDesc"
            + " FROM FinancialType ft"
            + " LEFT OUTER JOIN FinancialCode fc"
            + " ON ft.FinancialTypeID = fc.FinancialTypeID"
            + " ORDER BY ft.ObjectTypeID, ft.FinancialTypeID, fc.FinancialCodeID";
        try (Connection con = sqlHelper.getConnection();
                PreparedStatement pstm = con.prepareStatement(sql);
                ResultSet rs = pstm.executeQuery();) {
            java.util.Map result = null;
            java.util.Map finTypes = null;
            java.util.Vector finCodes = null;
            // this record
            Integer objTypeID = null;
            Integer finTypeID = null;
            String finTypeDesc = null;
            // prev record
            Integer prevObjTypeID = null;
            Integer prevFinTypeID = null;
            while (rs.next()) {
                objTypeID = (Integer) rs.getObject("ObjectTypeID");
                finTypeID = (Integer) rs.getObject("FinancialTypeID");
                finTypeDesc = rs.getString("FinancialTypeDesc");
                finTypeDesc = finTypeDesc == null ? null : finTypeDesc.trim();
                // update 135.sql (added FinancialObjectTypeID.UNDEFINED)
                // FinancialTypeID in FinancialCode table can be null
                // if ( finTypeID == null ) {
                // finTypeID = new Integer(0);
                // objTypeID = new Integer(0);
                // }
                if (result == null) {
                    result = new TreeMap(new CodeComparator());
                    prevObjTypeID = objTypeID;
                    prevFinTypeID = finTypeID;
                }
                // reset these maps if we moved to next object type/fin type
                if (!objTypeID.equals(prevObjTypeID))
                    finTypes = null;
                if (!finTypeID.equals(prevFinTypeID))
                    finCodes = null;
                // .. and create new ones
                if (finTypes == null) {
                    finTypes = new java.util.TreeMap(new CodeComparator());
                    result.put(objTypeID, finTypes);
                    // add null fin. type entry
                    finTypes.put(ReferenceCode.CODE_NONE, new java.util.Vector());// null );
                }
                if (finCodes == null) {
                    finCodes = new java.util.Vector();
                    finTypes.put(new ReferenceCode(finTypeID, finTypeDesc), finCodes);
                    // add null fin. code entry
                    finCodes.add(ReferenceCode.CODE_NONE);
                }
                // load finCodes entry with new finCodes
                int finCodeID = rs.getInt("FinancialCodeID");
                String finCode = rs.getString("FinancialCode");
                finCode = finCode == null ? null : finCode.trim();
                String finCodeDesc = rs.getString("FinancialCodeDesc");
                finCodeDesc = finCodeDesc == null ? null : finCodeDesc.trim();
                finCodes.add(new ReferenceCode(finCodeID, finCode, finCodeDesc));
                // update prev value
                prevFinTypeID = finTypeID;
                prevObjTypeID = objTypeID;
            }
            return result;
        } catch (SQLException e) {
            throw new ServiceException(e.getMessage());
        }
    }

    /**
     * CONTAINER structure Map( objType, Map( ReferenceCode( finTypeID,
     * finTypeDesc ), Vector( ReferenceCode( finCodeID, finCode, finCodeDesc ) ) ) )
     */
    public java.util.Map getFinancialObjectTypes() throws ServiceException {

        Connection con = null;
        PreparedStatement sql = null;
        ResultSet rs = null;

        try {
            con = sqlHelper.getConnection();
            String s = "SELECT"
                + " ft.ObjectTypeID, ft.FinancialTypeID, ft.FinancialTypeDesc,"
                + " fc.FinancialCodeID, fc.FinancialCode, fc.FinancialCodeDesc"
                + " FROM FinancialType ft"
                + " LEFT OUTER JOIN FinancialCode fc"
                + " ON ft.FinancialTypeID = fc.FinancialTypeID"
                + " ORDER BY ft.ObjectTypeID, ft.FinancialTypeID, fc.FinancialCodeID";

            sql = con.prepareStatement(s);
            rs = sql.executeQuery();

            java.util.Map result = null;
            java.util.Map finTypes = null;
            java.util.Vector finCodes = null;

            // this record
            Integer objTypeID = null;
            Integer finTypeID = null;
            String finTypeDesc = null;
            // prev record
            Integer prevObjTypeID = null;
            Integer prevFinTypeID = null;

            while (rs.next()) {

                objTypeID = (Integer) rs.getObject("ObjectTypeID");
                finTypeID = (Integer) rs.getObject("FinancialTypeID");
                finTypeDesc = rs.getString("FinancialTypeDesc");
                finTypeDesc = finTypeDesc == null ? null : finTypeDesc.trim();

                // update 135.sql (added FinancialObjectTypeID.UNDEFINED)
                // FinancialTypeID in FinancialCode table can be null
                // if ( finTypeID == null ) {
                // finTypeID = new Integer(0);
                // objTypeID = new Integer(0);
                // }

                if (result == null) {
                    result = new TreeMap(new CodeComparator());

                    prevObjTypeID = objTypeID;
                    prevFinTypeID = finTypeID;
                }

                // reset these maps if we moved to next object type/fin type
                if (!objTypeID.equals(prevObjTypeID))
                    finTypes = null;
                if (!finTypeID.equals(prevFinTypeID))
                    finCodes = null;

                // .. and create new ones
                if (finTypes == null) {
                    finTypes = new java.util.TreeMap(
                            new CodeComparator());
                    result.put(objTypeID, finTypes);

                    // add null fin. type entry
                    finTypes.put(ReferenceCode.CODE_NONE,
                            new java.util.Vector());// null );
                }

                if (finCodes == null) {
                    finCodes = new java.util.Vector();
                    finTypes.put(new ReferenceCode(finTypeID, finTypeDesc),
                            finCodes);

                    // add null fin. code entry
                    finCodes.add(ReferenceCode.CODE_NONE);
                }

                // load finCodes entry with new finCodes
                int finCodeID = rs.getInt("FinancialCodeID");
                String finCode = rs.getString("FinancialCode");
                finCode = finCode == null ? null : finCode.trim();
                String finCodeDesc = rs.getString("FinancialCodeDesc");
                finCodeDesc = finCodeDesc == null ? null : finCodeDesc.trim();

                finCodes
                        .add(new ReferenceCode(finCodeID, finCode, finCodeDesc));

                // update prev value
                prevFinTypeID = finTypeID;
                prevObjTypeID = objTypeID;

            }

            return result;

        } catch (SQLException e) {
            throw new ServiceException(e.getMessage());
        } finally {
            try {
                sqlHelper.close(rs, sql);
                if (con != null)
                    con.close();
            } catch (SQLException e) {
                throw new ServiceException(e.getMessage());
            }
        }

    }

Try With Resources try(Connection con=sqlHelper.getConnection(); PreparedStatement pstm=con.prepareStatement(sql); ResultSet rs=pstm.executeQuery()) in method public getFinancialObjectTypes() : Map from class au.com.totemsoft.myplanner.service.impl.UtilityServiceImpl


    public java.util.HashMap getLifeExpectancy(Integer countryCodeID)
            throws ServiceException {
        String sql = "SELECT Age, SexCodeID, LEValue"
            + " FROM LifeExpectancy" + " WHERE CountryCodeID = ?"
            + " ORDER BY Age, SexCodeID";
        try (Connection con = sqlHelper.getConnection();
                PreparedStatement pstm = con.prepareStatement(sql);) {
            pstm.setInt(1, countryCodeID.intValue());
            try (ResultSet rs = pstm.executeQuery();) {
                java.util.HashMap map = null;
                Integer age = null;
                double femaleLE = 0; // SexCode.FEMALE = 1
                double maleLE = 0; // SexCode.MALE = 2
                int count = 0;
                while (rs.next()) {
                    if (map == null)
                        map = new java.util.HashMap();
                    age = (Integer) rs.getObject("Age");
                    if (rs.getObject("SexCodeID").equals(SexCode.FEMALE))
                        femaleLE = rs.getDouble("LEValue");
                    else
                        maleLE = rs.getDouble("LEValue");
                    if (femaleLE != 0 && maleLE != 0) {
                        map.put(age, new double[] { femaleLE, maleLE });
                        femaleLE = 0;
                        maleLE = 0;
                        count = 0;
                    } else
                    // check that are only TWO entries for this age (female and male)
                    if (++count > 2)
                        throw new RuntimeException(
                            "Only TWO entries for this age are allowed (female and male): " + age.intValue());
                }
                return map;
            }
        } catch (SQLException e) {
            throw new ServiceException(e.getMessage());
        }
    }

    public java.util.HashMap getLifeExpectancy(Integer countryCodeID)
            throws ServiceException {

        Connection con = null;
        PreparedStatement sql = null;
        ResultSet rs = null;

        try {
            con = sqlHelper.getConnection();

            sql = con.prepareStatement("SELECT Age, SexCodeID, LEValue"
                    + " FROM LifeExpectancy" + " WHERE CountryCodeID = ?"
                    + " ORDER BY Age, SexCodeID");

            sql.setInt(1, countryCodeID.intValue());
            rs = sql.executeQuery();

            java.util.HashMap map = null;
            Integer age = null;
            double femaleLE = 0; // SexCode.FEMALE = 1
            double maleLE = 0; // SexCode.MALE = 2
            int count = 0;

            while (rs.next()) {

                if (map == null)
                    map = new java.util.HashMap();

                age = (Integer) rs.getObject("Age");

                if (rs.getObject("SexCodeID").equals(SexCode.FEMALE))
                    femaleLE = rs.getDouble("LEValue");
                else
                    maleLE = rs.getDouble("LEValue");

                if (femaleLE != 0 && maleLE != 0) {
                    map.put(age, new double[] { femaleLE, maleLE });
                    femaleLE = 0;
                    maleLE = 0;
                    count = 0;
                } else
                // check that are only TWO entries for this age (female and
                // male)
                if (++count > 2)
                    throw new RuntimeException(
                            "Only TWO entries for this age are allowed (female and male): "
                                    + age.intValue());

            }

            return map;

        } catch (SQLException e) {
            throw new ServiceException(e.getMessage());
        } finally {
            try {
                sqlHelper.close(rs, sql);
                if (con != null)
                    con.close();
            } catch (SQLException e) {
                throw new ServiceException(e.getMessage());
            }
        }

    }

Try With Resources try(ResultSet rs=pstm.executeQuery()) in method public getLifeExpectancy(countryCodeID Integer) : HashMap from class au.com.totemsoft.myplanner.service.impl.UtilityServiceImpl


    /**
     * TODO: virtual method, move to SQLServerHelper, etc
     */
    public String getDBServerVersion() throws ServiceException {
        try (Connection con = sqlHelper.getConnection();) {
            try (PreparedStatement pstm = con.prepareStatement("SELECT @@VERSION");
                    ResultSet rs = pstm.executeQuery();) {
                String dbServerVersion;
                if (rs.next())
                    dbServerVersion = rs.getString(1);
                else
                    dbServerVersion = "0"; // no version ??? , will never happened
                return dbServerVersion;
            }
        } catch (SQLException e) {
            throw new ServiceException(e.getMessage());
        }
    }

    /**
     * TODO: virtual method, move to SQLServerHelper, etc
     */
    public String getDBServerVersion() throws ServiceException {
        try {
            Connection con = sqlHelper.getConnection();
            PreparedStatement sql = null;
            ResultSet rs = null;

            try {
                sql = con
                        .prepareStatement("SELECT @@VERSION",
                                ResultSet.TYPE_FORWARD_ONLY,
                                ResultSet.CONCUR_READ_ONLY);

                rs = sql.executeQuery();

                String dbServerVersion;
                if (rs.next())
                    dbServerVersion = rs.getString(1);
                else
                    dbServerVersion = "0"; // no version ??? , will never happened
                return dbServerVersion;
            } finally {
                sqlHelper.close(rs, sql);
                if (con != null)
                    con.close();
            }

        } catch (SQLException e) {
            throw new ServiceException(e.getMessage());
        }

    }

Try With Resources try(Connection con=sqlHelper.getConnection()) in method public getDBServerVersion() : String from class au.com.totemsoft.myplanner.service.impl.UtilityServiceImpl


    /***************************************************************************
     * TODO: move it to ConnectionPool
     */
    public String getDBVersion() throws ServiceException {
        try (Connection con = sqlHelper.getConnection();) {
            String sql = "SELECT CurrentVersion FROM DBVersion"
                + " ORDER BY CurrentVersion DESC"; // most recent first
                //+ " ORDER BY DateCreated DESC"; // most recent first
            try (PreparedStatement pstm = con.prepareStatement(sql);
                    ResultSet rs = pstm.executeQuery();) {
                String dbVersion;
                if (rs.next())
                    dbVersion = rs.getString(1);
                else
                    dbVersion = "___???___"; // no version ??? , will never happened
                return dbVersion;
            }
        } catch (SQLException e) {
            throw new ServiceException(e.getMessage());
        }
    }

    /***************************************************************************
     * TODO: move it to ConnectionPool
     */
    public String getDBVersion() throws ServiceException {
        try {
            Connection con = sqlHelper.getConnection();
            PreparedStatement sql = null;
            ResultSet rs = null;

            try {
                sql = con.prepareStatement("SELECT CurrentVersion FROM DBVersion"
                        + " ORDER BY CurrentVersion DESC" // most recent first
                        //+ " ORDER BY DateCreated DESC" // most recent first
                , ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);

                rs = sql.executeQuery();

                String dbVersion;
                if (rs.next())
                    dbVersion = rs.getString(1);
                else
                    dbVersion = "___???___"; // no version ??? , will never happened
                return dbVersion;
            } finally {
                sqlHelper.close(rs, sql);
                if (con != null)
                    con.close();
            }
        } catch (SQLException e) {
            throw new ServiceException(e.getMessage());
        }
    }

Try With Resources try(PreparedStatement pstm=con.prepareStatement(sql); ResultSet rs=pstm.executeQuery()) in method public getDBVersion() : String from class au.com.totemsoft.myplanner.service.impl.UtilityServiceImpl


    public void addCode(String tableName, java.util.Map addData) throws ServiceException {
        String names = null;
        String values = null;
        java.util.Iterator iter = addData.entrySet().iterator();
        while (iter.hasNext()) {
            java.util.Map.Entry entry = (java.util.Map.Entry) iter.next();
            if (names == null)
                names = "";
            else
                names += ",";
            names += entry.getKey().toString();
            if (values == null)
                values = "";
            else
                values += ",";
            values += "?";
        }
        String sql = "INSERT INTO " + tableName + " ( " + names + " ) VALUES ( " + values + " )";
        try (Connection con = sqlHelper.getConnection();
                PreparedStatement pstm = con.prepareStatement(sql);) {
            Object[] values2 = addData.values().toArray();
            for (int i = 0; i < values2.length; i++)
                pstm.setObject(i + 1, values2[i]);
            pstm.executeUpdate();
        } catch (SQLException e) {
            throw new ServiceException(e.getMessage());
        }
    }

    public void addCode(String tableName, java.util.Map addData)
            throws ServiceException {
        Connection con = null;
        PreparedStatement sql = null;
        ResultSet rs = null;
        try {
            con = sqlHelper.getConnection();

            String names = null;
            String values = null;
            java.util.Iterator iter = addData.entrySet().iterator();
            while (iter.hasNext()) {
                java.util.Map.Entry entry = (java.util.Map.Entry) iter.next();

                if (names == null)
                    names = "";
                else
                    names += ",";
                names += entry.getKey().toString();

                if (values == null)
                    values = "";
                else
                    values += ",";
                values += "?";

            }

            sql = con.prepareStatement("INSERT INTO " + tableName + " ( "
                    + names + " ) VALUES ( " + values + " )");

            Object[] values2 = addData.values().toArray();
            for (int i = 0; i < values2.length; i++)
                sql.setObject(i + 1, values2[i]);

        } catch (SQLException e) {
            throw new ServiceException(e.getMessage());
        } finally {
            try {
                sqlHelper.close(rs, sql);
                if (con != null)
                    con.close();
            } catch (SQLException e) {
                throw new ServiceException(e.getMessage());
            }
        }

    }

Try With Resources try(Connection con=sqlHelper.getConnection(); PreparedStatement pstm=con.prepareStatement(sql)) in method public addCode(tableName String, addData Map) : void from class au.com.totemsoft.myplanner.service.impl.UtilityServiceImpl


    public void updateCode(String tableName, java.util.Map updateData, java.util.Map whereData) throws ServiceException {
        String values = null;
        java.util.Iterator iter = updateData.entrySet().iterator();
        while (iter.hasNext()) {
            java.util.Map.Entry entry = (java.util.Map.Entry) iter.next();
            if (values == null)
                values = "";
            else
                values += ",";
            values += entry.getKey().toString() + "=?";
        }
        String where = null;
        iter = whereData.entrySet().iterator();
        while (iter.hasNext()) {
            java.util.Map.Entry entry = (java.util.Map.Entry) iter.next();
            if (where == null)
                where = "";
            else
                where += " AND ";
            where += entry.getKey().toString() + "=?";
        }
        String sql = "UPDATE " + tableName + " SET " + values + " WHERE " + where;
        try (Connection con = sqlHelper.getConnection();
                PreparedStatement pstm = con.prepareStatement(sql);) {
            Object[] values2 = updateData.values().toArray();
            int j = 1;
            for (int i = 0; i < values2.length; i++)
                pstm.setObject(j++, values2[i]);
            values2 = whereData.values().toArray();
            for (int i = 0; i < values2.length; i++)
                pstm.setObject(j++, values2[i]);
            pstm.executeUpdate();
        } catch (SQLException e) {
            throw new ServiceException(e.getMessage());
        }
    }

    public void updateCode(String tableName, java.util.Map updateData,
            java.util.Map whereData) throws ServiceException {

        Connection con = null;
        PreparedStatement sql = null;
        ResultSet rs = null;
        try {
            con = sqlHelper.getConnection();

            String values = null;
            java.util.Iterator iter = updateData.entrySet().iterator();
            while (iter.hasNext()) {
                java.util.Map.Entry entry = (java.util.Map.Entry) iter.next();

                if (values == null)
                    values = "";
                else
                    values += ",";
                values += entry.getKey().toString() + "=?";

            }

            String where = null;
            iter = whereData.entrySet().iterator();
            while (iter.hasNext()) {
                java.util.Map.Entry entry = (java.util.Map.Entry) iter.next();

                if (where == null)
                    where = "";
                else
                    where += " AND ";
                where += entry.getKey().toString() + "=?";

            }

            sql = con.prepareStatement("UPDATE " + tableName + " SET " + values
                    + " WHERE " + where);

            Object[] values2 = updateData.values().toArray();
            int j = 1;
            for (int i = 0; i < values2.length; i++)
                sql.setObject(j++, values2[i]);

            values2 = whereData.values().toArray();
            for (int i = 0; i < values2.length; i++)
                sql.setObject(j++, values2[i]);

        } catch (SQLException e) {
            throw new ServiceException(e.getMessage());
        } finally {
            try {
                sqlHelper.close(rs, sql);
                if (con != null)
                    con.close();
            } catch (SQLException e) {
                throw new ServiceException(e.getMessage());
            }
        }

    }

Try With Resources try(Connection con=sqlHelper.getConnection(); PreparedStatement pstm=con.prepareStatement(sql)) in method public updateCode(tableName String, updateData Map, whereData Map) : void from class au.com.totemsoft.myplanner.service.impl.UtilityServiceImpl