Example usage for java.sql Date Date

List of usage examples for java.sql Date Date

Introduction

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

Prototype

public Date(long date) 

Source Link

Document

Allocates a Date object and initializes it to represent the specified number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT.

Usage

From source file:nl.ordina.bag.etl.dao.AbstractBAGDAO.java

@Override
public void update(final OpenbareRuimte openbareRuimte) throws DAOException {
    try {//from   www  .  j  av  a2 s  . c om
        jdbcTemplate.update(new PreparedStatementCreator() {
            @Override
            public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
                PreparedStatement ps = connection.prepareStatement("update bag_openbare_ruimte set"
                        + " aanduiding_record_inactief = ?," + " openbare_ruimte_naam = ?," + " officieel = ?,"
                        + " einddatum_tijdvak_geldigheid = ?," + " in_onderzoek = ?,"
                        + " openbare_ruimte_type = ?," + " bron_documentdatum = ?,"
                        + " bron_documentnummer = ?," + " openbareruimte_status = ?,"
                        + " bag_woonplaats_id = ?," + " verkorte_openbare_ruimte_naam = ?"
                        + " where bag_openbare_ruimte_id = ?" + " and aanduiding_record_correctie = ?"
                        + " and begindatum_tijdvak_geldigheid = ?");
                ps.setInt(1, openbareRuimte.getAanduidingRecordInactief().ordinal());
                ps.setString(2, openbareRuimte.getOpenbareRuimteNaam());
                ps.setInt(3, openbareRuimte.getOfficieel().ordinal());
                if (openbareRuimte.getEinddatumTijdvakGeldigheid() == null)
                    ps.setNull(4, Types.TIMESTAMP);
                else
                    ps.setTimestamp(4, new Timestamp(openbareRuimte.getEinddatumTijdvakGeldigheid().getTime()));
                ps.setInt(5, openbareRuimte.getInOnderzoek().ordinal());
                ps.setInt(6, openbareRuimte.getOpenbareRuimteType().ordinal());
                ps.setDate(7, new Date(openbareRuimte.getDocumentdatum().getTime()));
                ps.setString(8, openbareRuimte.getDocumentnummer());
                ps.setInt(9, openbareRuimte.getOpenbareruimteStatus().ordinal());
                ps.setLong(10, openbareRuimte.getGerelateerdeWoonplaats());
                ps.setString(11, openbareRuimte.getVerkorteOpenbareRuimteNaam());
                ps.setLong(12, openbareRuimte.getIdentificatie());
                ps.setLong(13, openbareRuimte.getAanduidingRecordCorrectie());
                ps.setTimestamp(14, new Timestamp(openbareRuimte.getBegindatumTijdvakGeldigheid().getTime()));
                return ps;
            }
        });
    } catch (DataAccessException e) {
        throw new DAOException("Error updating openbare ruimte: " + openbareRuimte.getIdentificatie(), e);
    }
}

From source file:com.sfs.whichdoctor.dao.PersonDAOImpl.java

/**
 * Update the region index for this person.
 *
 * @param guid the guid//from w  ww. j a  v  a2s . co m
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
public final void updateRegion(final int guid) throws WhichDoctorDaoException {

    int regionId = 0;

    try {
        final Date currentDate = new Date(Calendar.getInstance().getTimeInMillis());

        regionId = this.getJdbcTemplateReader().queryForInt(this.getSQL().getValue("person/loadEmployerRegion"),
                new Object[] { currentDate, currentDate, guid });

    } catch (IncorrectResultSizeDataAccessException ie) {
        dataLogger.debug("No results found for search: " + ie.getMessage());
    }

    // If no region id found, search to get the region for the person's address
    if (regionId == 0) {
        regionId = this.getAddressDAO().getRegionId(guid);
    }

    try {
        this.getSearchIndexDAO().update(guid, "Region", 0, 0, regionId);
    } catch (Exception e) {
        dataLogger.error("Error updating region index: " + e.getMessage());
    }
}

From source file:com.sfs.whichdoctor.dao.PersonDAOImpl.java

/**
 * Update the resident country index for this person.
 *
 * @param guid the guid//ww w  .j  a v a 2 s  .co  m
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
public final void updateResidentCountry(final int guid) throws WhichDoctorDaoException {

    int stateCountryId = 0;

    try {
        final Date currentDate = new Date(Calendar.getInstance().getTimeInMillis());

        stateCountryId = this.getJdbcTemplateReader().queryForInt(
                this.getSQL().getValue("person/loadEmployerCountry"),
                new Object[] { currentDate, currentDate, guid });

    } catch (IncorrectResultSizeDataAccessException ie) {
        dataLogger.debug("No results found for search: " + ie.getMessage());
    }

    // If no state/country id found, search to get the id for the person's address
    if (stateCountryId == 0) {
        stateCountryId = this.getAddressDAO().getStateCountryId(guid);
    }

    try {
        this.getSearchIndexDAO().update(guid, "Resident Country", 0, 0, stateCountryId);
    } catch (Exception e) {
        dataLogger.error("Error updating resident country index: " + e.getMessage());
    }
}

From source file:org.apache.phoenix.end2end.DateTimeIT.java

@Test
public void testProjectedUnsignedDateTimestampCompare() throws Exception {
    String tableName = generateUniqueName();
    String ddl = "CREATE TABLE IF NOT EXISTS " + tableName
            + " (k1 INTEGER PRIMARY KEY, dates UNSIGNED_DATE, timestamps TIMESTAMP)";
    conn.createStatement().execute(ddl);
    // Differ by date
    String dml = "UPSERT INTO " + tableName + " VALUES (1," + "TO_DATE('2004-02-04 00:10:10'),"
            + "TO_TIMESTAMP('2006-04-12 00:10:10'))";
    conn.createStatement().execute(dml);
    // Differ by time
    dml = "UPSERT INTO " + tableName + " VALUES (2," + "TO_DATE('2004-02-04 00:10:10'), "
            + "TO_TIMESTAMP('2004-02-04 15:10:20'))";
    conn.createStatement().execute(dml);
    // Differ by nanoseconds
    PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES (?, ?, ?)");
    stmt.setInt(1, 3);/*  ww  w  .jav a 2 s  .c o  m*/
    stmt.setDate(2, new Date(1000));
    Timestamp ts = new Timestamp(1000);
    ts.setNanos(100);
    stmt.setTimestamp(3, ts);
    stmt.execute();
    // Equality
    dml = "UPSERT INTO " + tableName + " VALUES (4," + "TO_DATE('2004-02-04 00:10:10'), "
            + "TO_TIMESTAMP('2004-02-04 00:10:10'))";
    conn.createStatement().execute(dml);
    conn.commit();

    ResultSet rs = conn.createStatement().executeQuery("SELECT dates = timestamps FROM " + tableName);
    assertTrue(rs.next());
    assertEquals(false, rs.getBoolean(1));
    assertTrue(rs.next());
    assertEquals(false, rs.getBoolean(1));
    assertTrue(rs.next());
    assertEquals(false, rs.getBoolean(1));
    assertTrue(rs.next());
    assertEquals(true, rs.getBoolean(1));
    assertFalse(rs.next());
}

From source file:nl.ordina.bag.etl.dao.AbstractBAGDAO.java

@Override
public void update(final Nummeraanduiding nummeraanduiding) throws DAOException {
    try {/*from  www  .  j av  a2 s  .  co m*/
        jdbcTemplate.update(new PreparedStatementCreator() {
            @Override
            public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
                PreparedStatement ps = connection.prepareStatement("update bag_nummeraanduiding set"
                        + " aanduiding_record_inactief = ?," + " huisnummer = ?," + " officieel = ?,"
                        + " huisletter = ?," + " huisnummertoevoeging = ?," + " postcode = ?,"
                        + " einddatum_tijdvak_geldigheid = ?," + " in_onderzoek = ?,"
                        + " type_adresseerbaar_object = ?," + " bron_documentdatum = ?,"
                        + " bron_documentnummer = ?," + " nummeraanduiding_status = ?,"
                        + " bag_woonplaats_id = ?," + " bag_openbare_ruimte_id = ?"
                        + " where bag_nummeraanduiding_id = ?" + " and aanduiding_record_correctie = ?"
                        + " and begindatum_tijdvak_geldigheid = ?");
                ps.setInt(1, nummeraanduiding.getAanduidingRecordInactief().ordinal());
                ps.setInt(2, nummeraanduiding.getHuisnummer());
                ps.setInt(3, nummeraanduiding.getOfficieel().ordinal());
                if (nummeraanduiding.getHuisletter() == null)
                    ps.setNull(4, Types.INTEGER);
                else
                    ps.setString(4, nummeraanduiding.getHuisletter());
                if (nummeraanduiding.getHuisnummertoevoeging() == null)
                    ps.setNull(5, Types.VARCHAR);
                else
                    ps.setString(5, nummeraanduiding.getHuisnummertoevoeging());
                if (nummeraanduiding.getPostcode() == null)
                    ps.setNull(6, Types.VARCHAR);
                else
                    ps.setString(6, nummeraanduiding.getPostcode());
                if (nummeraanduiding.getEinddatumTijdvakGeldigheid() == null)
                    ps.setNull(7, Types.TIMESTAMP);
                else
                    ps.setTimestamp(7,
                            new Timestamp(nummeraanduiding.getEinddatumTijdvakGeldigheid().getTime()));
                ps.setInt(8, nummeraanduiding.getInOnderzoek().ordinal());
                ps.setInt(9, nummeraanduiding.getTypeAdresseerbaarObject().ordinal());
                ps.setDate(10, new Date(nummeraanduiding.getDocumentdatum().getTime()));
                ps.setString(11, nummeraanduiding.getDocumentnummer());
                ps.setInt(12, nummeraanduiding.getNummeraanduidingStatus().ordinal());
                if (nummeraanduiding.getGerelateerdeWoonplaats() == null)
                    ps.setNull(13, Types.INTEGER);
                else
                    ps.setLong(13, nummeraanduiding.getGerelateerdeWoonplaats());
                ps.setLong(14, nummeraanduiding.getGerelateerdeOpenbareRuimte());
                ps.setLong(15, nummeraanduiding.getIdentificatie());
                ps.setLong(16, nummeraanduiding.getAanduidingRecordCorrectie());
                ps.setTimestamp(17, new Timestamp(nummeraanduiding.getBegindatumTijdvakGeldigheid().getTime()));
                return ps;
            }
        });
    } catch (DataAccessException e) {
        throw new DAOException("Error updating nummeraanduiding: " + nummeraanduiding.getIdentificatie(), e);
    }
}

From source file:dk.netarkivet.archive.arcrepositoryadmin.ReplicaCacheDatabase.java

/**
 * Method for updating a specific entry in the replicafileinfo table. Based on the filename, checksum and replica it
 * is verified whether a file is missing, corrupt or valid.
 *
 * @param filename Name of the file./*ww  w . j a  v a 2 s  .  c o  m*/
 * @param checksum The checksum of the file. Is allowed to be null, if no file is found.
 * @param replica The replica where the file exists.
 * @throws ArgumentNotValid If the filename is null or the empty string, or if the replica is null.
 */
@Override
public void updateChecksumInformationForFileOnReplica(String filename, String checksum, Replica replica)
        throws ArgumentNotValid {
    ArgumentNotValid.checkNotNullOrEmpty(filename, "String filename");
    ArgumentNotValid.checkNotNull(replica, "Replica replica");

    PreparedStatement statement = null;
    Connection connection = null;
    try {
        connection = ArchiveDBConnection.get();

        long guid = ReplicaCacheHelpers.retrieveGuidForFilenameOnReplica(filename, replica.getId(), connection);

        Date now = new Date(Calendar.getInstance().getTimeInMillis());

        // handle differently whether a checksum was retrieved.
        if (checksum == null) {
            // Set to MISSING! and do not update the checksum
            // (cannot insert null).
            String sql = "UPDATE replicafileinfo "
                    + "SET filelist_status = ?, checksum_status = ?, filelist_checkdatetime = ? "
                    + "WHERE replicafileinfo_guid = ?";
            statement = DBUtils.prepareStatement(connection, sql, FileListStatus.MISSING.ordinal(),
                    ChecksumStatus.UNKNOWN.ordinal(), now, guid);
        } else {
            String sql = "UPDATE replicafileinfo "
                    + "SET checksum = ?, filelist_status = ?, filelist_checkdatetime = ? "
                    + "WHERE replicafileinfo_guid = ?";
            statement = DBUtils.prepareStatement(connection, sql, checksum, FileListStatus.OK.ordinal(), now,
                    guid);
        }
        statement.executeUpdate();
        connection.commit();
    } catch (Exception e) {
        throw new IOFailure("Could not update single checksum entry.", e);
    } finally {
        DBUtils.closeStatementIfOpen(statement);
        if (connection != null) {
            ArchiveDBConnection.release(connection);
        }
    }
}

From source file:nl.ordina.bag.etl.dao.AbstractBAGDAO.java

@Override
public void update(final Pand pand) throws DAOException {
    try {/*from  www.ja  v  a2  s  .  c  om*/
        jdbcTemplate.update(new PreparedStatementCreator() {
            @Override
            public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
                PreparedStatement ps = connection.prepareStatement("update bag_pand set"
                        + " aanduiding_record_inactief = ?," + " officieel = ?," + " pand_geometrie = ?,"
                        + " bouwjaar = ?," + " pand_status = ?," + " einddatum_tijdvak_geldigheid = ?,"
                        + " in_onderzoek = ?," + " bron_documentdatum = ?," + " bron_documentnummer = ?"
                        + " where bag_pand_id = ?" + " and aanduiding_record_correctie = ?"
                        + " and begindatum_tijdvak_geldigheid = ?");
                ps.setInt(1, pand.getAanduidingRecordInactief().ordinal());
                ps.setInt(2, pand.getOfficieel().ordinal());
                ps.setString(3, pand.getPandGeometrie());
                ps.setInt(4, pand.getBouwjaar());
                ps.setString(5, pand.getPandStatus());
                if (pand.getEinddatumTijdvakGeldigheid() == null)
                    ps.setNull(6, Types.TIMESTAMP);
                else
                    ps.setTimestamp(6, new Timestamp(pand.getEinddatumTijdvakGeldigheid().getTime()));
                ps.setInt(7, pand.getInOnderzoek().ordinal());
                ps.setDate(8, new Date(pand.getDocumentdatum().getTime()));
                ps.setString(9, pand.getDocumentnummer());
                ps.setLong(10, pand.getIdentificatie());
                ps.setLong(11, pand.getAanduidingRecordCorrectie());
                ps.setTimestamp(12, new Timestamp(pand.getBegindatumTijdvakGeldigheid().getTime()));
                return ps;
            }
        });
    } catch (DataAccessException e) {
        throw new DAOException("Error updating pand: " + pand.getIdentificatie(), e);
    }
}

From source file:org.apache.phoenix.end2end.DateTimeIT.java

@Test
public void testProjectedUnsignedDateUnsignedTimestampCompare() throws Exception {
    String tableName = generateUniqueName();
    String ddl = "CREATE TABLE IF NOT EXISTS " + tableName
            + " (k1 INTEGER PRIMARY KEY, dates UNSIGNED_DATE, timestamps UNSIGNED_TIMESTAMP)";
    conn.createStatement().execute(ddl);
    // Differ by date
    String dml = "UPSERT INTO " + tableName + " VALUES (1," + "TO_DATE('2004-02-04 00:10:10'),"
            + "TO_TIMESTAMP('2006-04-12 00:10:10'))";
    conn.createStatement().execute(dml);
    // Differ by time
    dml = "UPSERT INTO " + tableName + " VALUES (2," + "TO_DATE('2004-02-04 00:10:10'), "
            + "TO_TIMESTAMP('2004-02-04 15:10:20'))";
    conn.createStatement().execute(dml);
    // Differ by nanoseconds
    PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES (?, ?, ?)");
    stmt.setInt(1, 3);/* ww  w .  ja  v a  2 s  .c o  m*/
    stmt.setDate(2, new Date(1000));
    Timestamp ts = new Timestamp(1000);
    ts.setNanos(100);
    stmt.setTimestamp(3, ts);
    stmt.execute();
    // Equality
    dml = "UPSERT INTO " + tableName + " VALUES (4," + "TO_DATE('2004-02-04 00:10:10'), "
            + "TO_TIMESTAMP('2004-02-04 00:10:10'))";
    conn.createStatement().execute(dml);
    conn.commit();

    ResultSet rs = conn.createStatement().executeQuery("SELECT dates = timestamps FROM " + tableName);
    assertTrue(rs.next());
    assertEquals(false, rs.getBoolean(1));
    assertTrue(rs.next());
    assertEquals(false, rs.getBoolean(1));
    assertTrue(rs.next());
    assertEquals(false, rs.getBoolean(1));
    assertTrue(rs.next());
    assertEquals(true, rs.getBoolean(1));
    assertFalse(rs.next());
}

From source file:Logica.Usuario.java

/**
 *
 * @param d//ww w . ja v a  2  s.c o  m
 * @return
 * @throws RemoteException
 *
 * Registra el descargo de un tem en la base de datos.
 */
@Override
public boolean realizarDescargo(descargo d) throws RemoteException {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Biot_ServerPU");
    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    String statement = "INSERT INTO DESCARGO(FECHA, ID_usuario, AREA, CANTIDAD, CINTERNO) VALUES (?,?,?,?,?)";
    boolean valido = false;
    try {
        con = Conexion.conexion.getConnection();
        ps = con.prepareStatement(statement);
        ps.setDate(1, new Date(d.getFecha().getTimeInMillis()));
        ps.setString(2, d.getId());
        ps.setString(3, d.getArea());
        ps.setFloat(4, d.getCantidad());
        ps.setString(5, d.getCinterno());
        ps.executeUpdate();
        this.updateCantidad(d.getCinterno(), d.getCantidad() * -1);
        valido = true;

    } catch (SQLException ex) {
        Logger.getLogger(Usuario.class.getName()).log(Level.SEVERE, null, ex);
    } finally {

        try {
            if (ps != null) {
                ps.close();
            }
            if (rs != null) {
                rs.close();
            }
            if (con != null) {
                con.close();
            }
        } catch (SQLException ex) {
            System.out.println("Error cerrando conexion");
        }
    }
    return valido;
}

From source file:com.ichi2.anki.SyncClient.java

private JSONObject bundleStats() {
    Log.i(AnkiDroidApp.TAG, "bundleStats");

    JSONObject bundledStats = new JSONObject();

    // Get daily stats since the last day the deck was synchronized
    Date lastDay = new Date(java.lang.Math.max(0, (long) (mDeck.getLastSync() - 60 * 60 * 24) * 1000));
    Log.i(AnkiDroidApp.TAG, "lastDay = " + lastDay.toString());
    ArrayList<Long> ids = AnkiDatabaseManager.getDatabase(mDeck.getDeckPath()).queryColumn(Long.class,
            "SELECT id FROM stats WHERE type = 1 and day >= \"" + lastDay.toString() + "\"", 0);

    try {/*from  ww w . j  a v  a2s  . co m*/
        Stats stat = new Stats(mDeck);
        // Put global stats
        bundledStats.put("global", Stats.globalStats(mDeck).bundleJson());
        // Put daily stats
        JSONArray dailyStats = new JSONArray();
        for (Long id : ids) {
            // Update stat with the values of the stat with id ids.get(i)
            stat.fromDB(id);
            // Bundle this stat and add it to dailyStats
            dailyStats.put(stat.bundleJson());
        }
        bundledStats.put("daily", dailyStats);
    } catch (SQLException e) {
        Log.i(AnkiDroidApp.TAG, "SQLException = " + e.getMessage());
    } catch (JSONException e) {
        Log.i(AnkiDroidApp.TAG, "JSONException = " + e.getMessage());
    }

    Log.i(AnkiDroidApp.TAG, "Stats =");
    Utils.printJSONObject(bundledStats, false);

    return bundledStats;
}