Example usage for java.sql PreparedStatement setDate

List of usage examples for java.sql PreparedStatement setDate

Introduction

In this page you can find the example usage for java.sql PreparedStatement setDate.

Prototype

void setDate(int parameterIndex, java.sql.Date x) throws SQLException;

Source Link

Document

Sets the designated parameter to the given java.sql.Date value using the default time zone of the virtual machine that is running the application.

Usage

From source file:org.gbif.harvest.portal.synchronise.dao.jdbc.RawOccurrenceRecordDaoImpl.java

/**
 * @see org.gbif.harvest.portal.synchronise.dao.RawOccurrenceRecordDao#updateOrCreate(org.gbif.harvest.portal.synchronise.model.RawOccurrenceRecord)
 *///w  ww  .  j a va2 s  .  c  om
public long updateOrCreate(final RawOccurrenceRecord rawOccurrenceRecord) {
    if (rawOccurrenceRecord.getId() <= 0) {
        return create(rawOccurrenceRecord);
    } else {
        getJdbcTemplate().update(new PreparedStatementCreator() {

            Timestamp updateTime = new Timestamp(System.currentTimeMillis());

            public PreparedStatement createPreparedStatement(Connection conn) throws SQLException {
                PreparedStatement ps = conn.prepareStatement(RawOccurrenceRecordDaoImpl.UPDATE_SQL);
                ps.setLong(1, rawOccurrenceRecord.getDataProviderId());
                ps.setLong(2, rawOccurrenceRecord.getDataResourceId());
                ps.setLong(3, rawOccurrenceRecord.getResourceAccessPointId());
                ps.setString(4, rawOccurrenceRecord.getInstitutionCode());
                ps.setString(5, rawOccurrenceRecord.getCollectionCode());
                ps.setString(6, rawOccurrenceRecord.getCatalogueNumber());
                // ensure line breaking characters are replaced with a space, this breaks the scroop-in (import
                // of mysql tables into hadoop)
                ps.setString(7,
                        StringUtils
                                .trimToNull(StringUtils.replace(
                                        StringUtils.replace(StringUtils.replace(
                                                rawOccurrenceRecord.getScientificName(), "\n", " "), "\r", " "),
                                        "\t", " ")));
                ps.setString(8,
                        StringUtils.trimToNull(StringUtils.replace(StringUtils.replace(
                                StringUtils.replace(rawOccurrenceRecord.getAuthor(), "\n", " "), "\r", " "),
                                "\t", " ")));
                ps.setString(9,
                        StringUtils.trimToNull(StringUtils.replace(StringUtils.replace(
                                StringUtils.replace(rawOccurrenceRecord.getRank(), "\n", " "), "\r", " "), "\t",
                                " ")));
                ps.setString(10,
                        StringUtils
                                .trimToNull(StringUtils.replace(
                                        StringUtils.replace(StringUtils.replace(
                                                rawOccurrenceRecord.getKingdom(), "\n", " "), "\r", " "),
                                        "\t", " ")));
                ps.setString(11,
                        StringUtils.trimToNull(StringUtils.replace(StringUtils.replace(
                                StringUtils.replace(rawOccurrenceRecord.getPhylum(), "\n", " "), "\r", " "),
                                "\t", " ")));
                ps.setString(12,
                        StringUtils.trimToNull(StringUtils.replace(StringUtils.replace(
                                StringUtils.replace(rawOccurrenceRecord.getKlass(), "\n", " "), "\r", " "),
                                "\t", " ")));
                ps.setString(13,
                        StringUtils.trimToNull(StringUtils.replace(StringUtils.replace(
                                StringUtils.replace(rawOccurrenceRecord.getOrder(), "\n", " "), "\r", " "),
                                "\t", " ")));
                ps.setString(14,
                        StringUtils.trimToNull(StringUtils.replace(StringUtils.replace(
                                StringUtils.replace(rawOccurrenceRecord.getFamily(), "\n", " "), "\r", " "),
                                "\t", " ")));
                ps.setString(15,
                        StringUtils.trimToNull(StringUtils.replace(StringUtils.replace(
                                StringUtils.replace(rawOccurrenceRecord.getGenus(), "\n", " "), "\r", " "),
                                "\t", " ")));
                ps.setString(16,
                        StringUtils
                                .trimToNull(StringUtils.replace(
                                        StringUtils.replace(StringUtils.replace(
                                                rawOccurrenceRecord.getSpecies(), "\n", " "), "\r", " "),
                                        "\t", " ")));
                ps.setString(17,
                        StringUtils
                                .trimToNull(StringUtils.replace(
                                        StringUtils.replace(StringUtils.replace(
                                                rawOccurrenceRecord.getSubspecies(), "\n", " "), "\r", " "),
                                        "\t", " ")));
                ps.setString(18,
                        StringUtils
                                .trimToNull(StringUtils.replace(
                                        StringUtils.replace(StringUtils.replace(
                                                rawOccurrenceRecord.getLatitude(), "\n", " "), "\r", " "),
                                        "\t", " ")));
                ps.setString(19,
                        StringUtils
                                .trimToNull(StringUtils.replace(
                                        StringUtils.replace(StringUtils.replace(
                                                rawOccurrenceRecord.getLongitude(), "\n", " "), "\r", " "),
                                        "\t", " ")));
                ps.setString(20,
                        StringUtils.trimToNull(StringUtils.replace(
                                StringUtils.replace(StringUtils.replace(
                                        rawOccurrenceRecord.getLatLongPrecision(), "\n", " "), "\r", " "),
                                "\t", " ")));
                ps.setString(21,
                        StringUtils
                                .trimToNull(StringUtils.replace(
                                        StringUtils.replace(StringUtils.replace(
                                                rawOccurrenceRecord.getMinAltitude(), "\n", " "), "\r", " "),
                                        "\t", " ")));
                ps.setString(22,
                        StringUtils
                                .trimToNull(StringUtils.replace(
                                        StringUtils.replace(StringUtils.replace(
                                                rawOccurrenceRecord.getMaxAltitude(), "\n", " "), "\r", " "),
                                        "\t", " ")));
                ps.setString(23,
                        StringUtils.trimToNull(StringUtils.replace(
                                StringUtils.replace(StringUtils.replace(
                                        rawOccurrenceRecord.getAltitudePrecision(), "\n", " "), "\r", " "),
                                "\t", " ")));
                ps.setString(24,
                        StringUtils
                                .trimToNull(StringUtils.replace(
                                        StringUtils.replace(StringUtils.replace(
                                                rawOccurrenceRecord.getMinDepth(), "\n", " "), "\r", " "),
                                        "\t", " ")));
                ps.setString(25,
                        StringUtils
                                .trimToNull(StringUtils.replace(
                                        StringUtils.replace(StringUtils.replace(
                                                rawOccurrenceRecord.getMaxDepth(), "\n", " "), "\r", " "),
                                        "\t", " ")));
                ps.setString(26,
                        StringUtils
                                .trimToNull(StringUtils.replace(
                                        StringUtils.replace(StringUtils.replace(
                                                rawOccurrenceRecord.getDepthPrecision(), "\n", " "), "\r", " "),
                                        "\t", " ")));
                ps.setString(27,
                        StringUtils.trimToNull(StringUtils.replace(
                                StringUtils.replace(StringUtils.replace(
                                        rawOccurrenceRecord.getContinentOrOcean(), "\n", " "), "\r", " "),
                                "\t", " ")));
                ps.setString(28,
                        StringUtils
                                .trimToNull(StringUtils.replace(
                                        StringUtils.replace(StringUtils.replace(
                                                rawOccurrenceRecord.getCountry(), "\n", " "), "\r", " "),
                                        "\t", " ")));
                ps.setString(29,
                        StringUtils.trimToNull(StringUtils.replace(
                                StringUtils.replace(StringUtils.replace(
                                        rawOccurrenceRecord.getStateOrProvince(), "\n", " "), "\r", " "),
                                "\t", " ")));
                ps.setString(30,
                        StringUtils.trimToNull(StringUtils.replace(StringUtils.replace(
                                StringUtils.replace(rawOccurrenceRecord.getCounty(), "\n", " "), "\r", " "),
                                "\t", " ")));
                ps.setString(31,
                        StringUtils
                                .trimToNull(StringUtils.replace(
                                        StringUtils.replace(StringUtils.replace(
                                                rawOccurrenceRecord.getCollectorName(), "\n", " "), "\r", " "),
                                        "\t", " ")));
                ps.setString(32,
                        StringUtils
                                .trimToNull(StringUtils.replace(
                                        StringUtils.replace(StringUtils.replace(
                                                rawOccurrenceRecord.getLocality(), "\n", " "), "\r", " "),
                                        "\t", " ")));
                ps.setString(33,
                        StringUtils.trimToNull(StringUtils.replace(StringUtils.replace(
                                StringUtils.replace(rawOccurrenceRecord.getYear(), "\n", " "), "\r", " "), "\t",
                                " ")));
                ps.setString(34,
                        StringUtils.trimToNull(StringUtils.replace(StringUtils.replace(
                                StringUtils.replace(rawOccurrenceRecord.getMonth(), "\n", " "), "\r", " "),
                                "\t", " ")));
                ps.setString(35,
                        StringUtils.trimToNull(StringUtils.replace(StringUtils.replace(
                                StringUtils.replace(rawOccurrenceRecord.getDay(), "\n", " "), "\r", " "), "\t",
                                " ")));
                ps.setString(36,
                        StringUtils
                                .trimToNull(StringUtils.replace(
                                        StringUtils.replace(StringUtils.replace(
                                                rawOccurrenceRecord.getBasisOfRecord(), "\n", " "), "\r", " "),
                                        "\t", " ")));
                ps.setString(37,
                        StringUtils
                                .trimToNull(StringUtils.replace(
                                        StringUtils.replace(StringUtils.replace(
                                                rawOccurrenceRecord.getIdentifierName(), "\n", " "), "\r", " "),
                                        "\t", " ")));
                ps.setDate(38, createSQLDate(rawOccurrenceRecord.getDateIdentified()));
                ps.setString(39,
                        StringUtils
                                .trimToNull(StringUtils.replace(
                                        StringUtils.replace(StringUtils.replace(
                                                rawOccurrenceRecord.getUnitQualifier(), "\n", " "), "\r", " "),
                                        "\t", " ")));
                ps.setTimestamp(40, updateTime);
                ps.setLong(41, rawOccurrenceRecord.getId());
                return ps;
            }
        });
        return rawOccurrenceRecord.getId();
    }
}