@Override public boolean update(PostingLocation postingLocation) throws SQLException { if (postingLocation == null) { return false; } Connection connection = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null; try { connection = this.daoFactory.getConnection(); final Object[] values = { postingLocation.getEmail(), postingLocation.getActive(), postingLocation.getLocation_fk() }; preparedStatement = DAOUtil.prepareStatement(connection, this.SQL_UPDATE, false, values); Globals.crawlerLogManager.writeLog(preparedStatement.toString()); preparedStatement.executeUpdate(); return true; } catch (final SQLException e) { Globals.crawlerLogManager.writeLog( "Fails to update email " + postingLocation.getEmail() + " in posting_location for id " + postingLocation.getLocation_fk()); Globals.crawlerLogManager.writeLog(e.getMessage()); return false; } finally { DAOUtil.close(connection, preparedStatement, resultSet); } }
@Override public boolean create(PostingLocation location) throws SQLException { if (!location.isValid()) { return false; } Connection connection = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null; try { connection = this.daoFactory.getConnection(); final Object[] values = { location.getState(), location.getCity(), location.getLatitude(), location.getLongitude(), location.getLocation_fk(), location.getLocation_link_fk(), location.getDatePosted(), location.getTimePosted(), location.getPosting_body(), location.getTitle(), location.getUrl(), location.getActive(), location.getEmail() }; preparedStatement = DAOUtil.prepareStatement(connection, this.SQL_INSERT, false, values); Globals.crawlerLogManager.writeLog(preparedStatement.toString()); preparedStatement.executeUpdate(); return true; } catch (final SQLException e) { Globals.crawlerLogManager.writeLog("Insert into table posting_location fails"); Globals.crawlerLogManager.writeLog(e.getMessage()); return false; } finally { DAOUtil.close(connection, preparedStatement, resultSet); } }