Hello, please help me call the close method, I understand that maybe it’s easy and it’s easy for a person with experience, you need to close the main in the main after calling the updateImages method, there is a close() method for this, since getImagesDAO() already creates an instance class, it is necessary to close it after the method has worked
public class DAOFactory implements DAOFactotyInterface { Connection connection = null; public Connection getConnection() throws DAOException { //получение соединения } return connection; } @Override public ImagesDAO getImagesDAO() throws DAOException { return new MySQLImagesDAO(getConnection()); public class MySQLImagesDAO implements ImagesDAO { private Connection connection = null; private PreparedStatement preparedStatement = null; public MySQLImagesDAO(Connection connection) { this.connection = connection; } private void getPreparedStatement(String sql) throws DAOException { if (preparedStatement == null) { try { preparedStatement = connection.prepareStatement(sql); } catch (Exception e) { throw new DAOException("Get preparedStatment failed.", e); } } } public void updateImages(Images images) throws DAOException { //метод update } }public void close() throws DAOException { //закрытие ps и соединения } public class Main { public static void main (String[] args){ DAOFactory test = new DAOFactory(); Images images = new Images(); images.setIdProfile(1); images.setAvatar("testLink"); images.setId(1); try { test.getImagesDAO().updateImages(images); //close? } catch (DAOException e) { e.printStackTrace(); } }