@Override public long insert(ManagerPanel panel, int userId) throws DbException { PreparedStatement ps = null; long result; try { prepareConnection(); ps = connection.prepareStatement(MANAGER_INSERT, Statement.RETURN_GENERATED_KEYS); ps.setInt(1, userId); ps.setDouble(2, panel.getSummaryFinRes().getAmount()); ps.executeUpdate(); try (ResultSet rs = ps.getGeneratedKeys()) { if (rs.next()) { result = rs.getLong(1); } else { throw new DbException( "Inserting failed on query: '" + MANAGER_INSERT + "' no ID obtained."); } } } catch (SQLException e) { throw new DbException("Can't execute SQL = '" + MANAGER_INSERT + "'", e); } finally { daoHelper.closeDataBaseEntities(ps, null, connection); } return result; }
@Override public void update(ManagerPanel panel, int userId) throws DbException { PreparedStatement ps = null; try { prepareConnection(); ps = connection.prepareStatement(MANAGER_UPDATE); ps.setDouble(1, panel.getSummaryFinRes().getAmount()); ps.setInt(2, userId); ps.executeUpdate(); } catch (SQLException e) { throw new DbException("Can't execute SQL = '" + MANAGER_UPDATE + "'", e); } finally { daoHelper.closeDataBaseEntities(ps, null, connection); } }