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:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.ChartHelper.java

/***********************************************************************************************
 * Create a dummy TimeSeriesDataItem at the origin of the Domain.
 *
 * @param timeseriescollection//w  ww .  ja  v a 2  s. co m
 * @param timeseries
 * @param domainstart
 * @param debug
 *
 * @return TimeSeriesDataItem
 */

public static TimeSeriesDataItem createDummyTimeSeriesDataItemAtOrigin(
        final TimeSeriesCollection timeseriescollection, final TimeSeries timeseries, final int domainstart,
        final boolean debug) {
    final String SOURCE = "ChartHelper.createDummyTimeSeriesDataItemAtOrigin() [domainstart=" + domainstart
            + "]";

    LOGGER.debug(debug, SOURCE);

    return new TimeSeriesDataItem(
            RegularTimePeriod.createInstance(timeseries.getTimePeriodClass(),
                    new Date(calculateDomainSliderMillis(ChartUIComponentPlugin.DOMAIN_SLIDER_MINIMUM,
                            ChartUIComponentPlugin.DOMAIN_SLIDER_MAXIMUM, domainstart,
                            timeseriescollection.getDomainLowerBound(true),
                            timeseriescollection.getDomainUpperBound(true), debug)),
                    TimeZone.getDefault()),
            timeseries.getMinY());
}

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

@Test
public void testDateSubtractionCompareDate() throws Exception {
    String tablename = generateUniqueName();
    String tenantId = getOrganizationId();
    String query = "SELECT feature FROM " + tablename + " WHERE organization_id = ? and date - 1 >= ?";
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    Connection conn = DriverManager.getConnection(getUrl(), props);
    try {//w ww . ja va2  s. c  o m
        Date startDate = new Date(System.currentTimeMillis());
        Date endDate = new Date(startDate.getTime() + 9 * QueryConstants.MILLIS_IN_DAY);
        initDateTableValues(tablename, tenantId, getSplits(tenantId), startDate);
        PreparedStatement statement = conn.prepareStatement(query);
        statement.setString(1, tenantId);
        statement.setDate(2, endDate);
        ResultSet rs = statement.executeQuery();
        assertTrue(rs.next());
        assertEquals("F", rs.getString(1));
        assertFalse(rs.next());
    } finally {
        conn.close();
    }
}

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

@Test
public void testDateAddCompareDate() throws Exception {
    String tablename = generateUniqueName();
    String tenantId = getOrganizationId();
    String query = "SELECT feature FROM " + tablename + " WHERE organization_id = ? and date + 1 >= ?";
    Connection conn = DriverManager.getConnection(url);
    try {/*from  w  ww .  ja v  a 2 s .com*/
        Date startDate = new Date(System.currentTimeMillis());
        Date endDate = new Date(startDate.getTime() + 8 * QueryConstants.MILLIS_IN_DAY);
        initDateTableValues(tablename, tenantId, getSplits(tenantId), startDate);
        PreparedStatement statement = conn.prepareStatement(query);
        statement.setString(1, tenantId);
        statement.setDate(2, endDate);
        ResultSet rs = statement.executeQuery();
        assertTrue(rs.next());
        assertEquals("E", rs.getString(1));
        assertTrue(rs.next());
        assertEquals("F", rs.getString(1));
        assertFalse(rs.next());
    } finally {
        conn.close();
    }
}

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

@Override
public void update(final Nummeraanduiding origineel, final Nummeraanduiding mutation) throws DAOException {
    try {//from  w  w w .  j a v 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 = ?," + " aanduiding_record_correctie = ?,"
                        + " 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, mutation.getAanduidingRecordInactief().ordinal());
                ps.setLong(2, mutation.getAanduidingRecordCorrectie());
                ps.setInt(3, mutation.getHuisnummer());
                ps.setInt(4, mutation.getOfficieel().ordinal());
                if (mutation.getHuisletter() == null)
                    ps.setNull(5, Types.INTEGER);
                else
                    ps.setString(5, mutation.getHuisletter());
                if (mutation.getHuisnummertoevoeging() == null)
                    ps.setNull(6, Types.VARCHAR);
                else
                    ps.setString(6, mutation.getHuisnummertoevoeging());
                if (mutation.getPostcode() == null)
                    ps.setNull(7, Types.VARCHAR);
                else
                    ps.setString(7, mutation.getPostcode());
                if (mutation.getEinddatumTijdvakGeldigheid() == null)
                    ps.setNull(8, Types.TIMESTAMP);
                else
                    ps.setTimestamp(8, new Timestamp(mutation.getEinddatumTijdvakGeldigheid().getTime()));
                ps.setInt(9, mutation.getInOnderzoek().ordinal());
                ps.setInt(10, mutation.getTypeAdresseerbaarObject().ordinal());
                ps.setDate(11, new Date(mutation.getDocumentdatum().getTime()));
                ps.setString(12, mutation.getDocumentnummer());
                ps.setInt(13, mutation.getNummeraanduidingStatus().ordinal());
                if (mutation.getGerelateerdeWoonplaats() == null)
                    ps.setNull(14, Types.INTEGER);
                else
                    ps.setLong(14, mutation.getGerelateerdeWoonplaats());
                ps.setLong(15, mutation.getGerelateerdeOpenbareRuimte());
                ps.setLong(16, origineel.getIdentificatie());
                ps.setLong(17, origineel.getAanduidingRecordCorrectie());
                ps.setTimestamp(18, new Timestamp(origineel.getBegindatumTijdvakGeldigheid().getTime()));
                return ps;
            }
        });
    } catch (DataAccessException e) {
        throw new DAOException("Error updating nummeraanduiding: " + origineel.getIdentificatie(), e);
    }
}

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

@Test
public void testCurrentDate() throws Exception {
    String tablename = generateUniqueName();
    String tenantId = getOrganizationId();
    String query = "SELECT feature FROM " + tablename
            + " WHERE organization_id = ? and \"DATE\" - current_date() > 8";
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    Connection conn = DriverManager.getConnection(getUrl(), props);
    try {//from  w ww.j  a v  a  2  s.  c o  m
        Date startDate = new Date(System.currentTimeMillis());
        initDateTableValues(tablename, tenantId, getSplits(tenantId), startDate);
        PreparedStatement statement = conn.prepareStatement(query);
        statement.setString(1, tenantId);
        ResultSet rs = statement.executeQuery();
        assertTrue(rs.next());
        assertEquals("F", rs.getString(1));
        assertFalse(rs.next());
    } finally {
        conn.close();
    }
}

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

@Test
public void testCurrentTime() throws Exception {
    String tablename = generateUniqueName();
    String tenantId = getOrganizationId();
    String query = "SELECT feature FROM " + tablename
            + " WHERE organization_id = ? and \"DATE\" - current_time() > 8";
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    Connection conn = DriverManager.getConnection(getUrl(), props);
    try {//w w w .j av  a2s .co  m
        Date startDate = new Date(System.currentTimeMillis());
        initDateTableValues(tablename, tenantId, getSplits(tenantId), startDate);
        PreparedStatement statement = conn.prepareStatement(query);
        statement.setString(1, tenantId);
        ResultSet rs = statement.executeQuery();
        assertTrue(rs.next());
        assertEquals("F", rs.getString(1));
        assertFalse(rs.next());
    } finally {
        conn.close();
    }
}

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

@Override
public void update(final Pand origineel, final Pand mutation) throws DAOException {
    try {/*  www .  j a va 2  s.co m*/
        jdbcTemplate.update(new PreparedStatementCreator() {
            @Override
            public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
                PreparedStatement ps = connection.prepareStatement("update bag_pand set"
                        + " aanduiding_record_inactief = ?," + " aanduiding_record_correctie = ?,"
                        + " 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, mutation.getAanduidingRecordInactief().ordinal());
                ps.setLong(2, mutation.getAanduidingRecordCorrectie());
                ps.setInt(3, mutation.getOfficieel().ordinal());
                ps.setString(4, mutation.getPandGeometrie());
                ps.setInt(5, mutation.getBouwjaar());
                ps.setString(6, mutation.getPandStatus());
                if (mutation.getEinddatumTijdvakGeldigheid() == null)
                    ps.setNull(7, Types.TIMESTAMP);
                else
                    ps.setTimestamp(7, new Timestamp(mutation.getEinddatumTijdvakGeldigheid().getTime()));
                ps.setInt(8, mutation.getInOnderzoek().ordinal());
                ps.setDate(9, new Date(mutation.getDocumentdatum().getTime()));
                ps.setString(10, mutation.getDocumentnummer());
                ps.setLong(11, origineel.getIdentificatie());
                ps.setLong(12, origineel.getAanduidingRecordCorrectie());
                ps.setTimestamp(13, new Timestamp(origineel.getBegindatumTijdvakGeldigheid().getTime()));
                return ps;
            }
        });
    } catch (DataAccessException e) {
        throw new DAOException("Error updating pand: " + origineel.getIdentificatie(), e);
    }
}

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

@Override
public void update(final Verblijfsobject origineel, final Verblijfsobject mutation) throws DAOException {
    try {//w ww .  ja va 2 s.  c  o  m
        transactionTemplate.execute(new TransactionCallbackWithoutResult() {
            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                jdbcTemplate.update(new PreparedStatementCreator() {
                    @Override
                    public PreparedStatement createPreparedStatement(Connection connection)
                            throws SQLException {
                        PreparedStatement ps = connection.prepareStatement("update bag_verblijfsobject set"
                                + " aanduiding_record_inactief = ?," + " aanduiding_record_correctie = ?,"
                                + " officieel = ?," + " verblijfsobject_geometrie = ?,"
                                + " oppervlakte_verblijfsobject = ?," + " verblijfsobject_status = ?,"
                                + " einddatum_tijdvak_geldigheid = ?," + " in_onderzoek = ?,"
                                + " bron_documentdatum = ?," + " bron_documentnummer = ?,"
                                + " bag_nummeraanduiding_id = ?" + " where bag_verblijfsobject_id = ?"
                                + " and aanduiding_record_correctie = ?"
                                + " and begindatum_tijdvak_geldigheid = ?");
                        ps.setInt(1, mutation.getAanduidingRecordInactief().ordinal());
                        ps.setLong(2, mutation.getAanduidingRecordCorrectie());
                        ps.setInt(3, mutation.getOfficieel().ordinal());
                        ps.setString(4, mutation.getVerblijfsobjectGeometrie());
                        ps.setInt(5, mutation.getOppervlakteVerblijfsobject());
                        ps.setInt(6, mutation.getVerblijfsobjectStatus().ordinal());
                        if (mutation.getEinddatumTijdvakGeldigheid() == null)
                            ps.setNull(7, Types.TIMESTAMP);
                        else
                            ps.setTimestamp(7,
                                    new Timestamp(mutation.getEinddatumTijdvakGeldigheid().getTime()));
                        ps.setInt(8, mutation.getInOnderzoek().ordinal());
                        ps.setDate(9, new Date(mutation.getDocumentdatum().getTime()));
                        ps.setString(10, mutation.getDocumentnummer());
                        ps.setLong(11, mutation.getHoofdAdres());
                        ps.setLong(12, origineel.getIdentificatie());
                        ps.setLong(13, origineel.getAanduidingRecordCorrectie());
                        ps.setTimestamp(14,
                                new Timestamp(origineel.getBegindatumTijdvakGeldigheid().getTime()));
                        return ps;
                    }
                });
                deleteGebruikersdoelen(origineel);
                insertGebruikersdoelen(mutation);
                deleteNevenadressen(TypeAdresseerbaarObject.VERBLIJFSOBJECT, origineel);
                insertNevenadressen(TypeAdresseerbaarObject.VERBLIJFSOBJECT, mutation);
                deleteGerelateerdePanden(origineel);
                insertGerelateerdePanden(mutation);
            }
        });
    } catch (DataAccessException e) {
        throw new DAOException("Error updating verblijfsobject: " + origineel.getIdentificatie(), e);
    }
}

From source file:org.apache.phoenix.query.BaseTest.java

protected static void populateMultiCFTestTable(String tableName, Date date) throws SQLException {
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    Connection conn = DriverManager.getConnection(getUrl(), props);
    try {/* www  . jav  a  2 s .  c  o  m*/
        String upsert = "UPSERT INTO " + tableName + " VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
        PreparedStatement stmt = conn.prepareStatement(upsert);
        stmt.setString(1, "varchar1");
        stmt.setString(2, "char1");
        stmt.setInt(3, 1);
        stmt.setLong(4, 1L);
        stmt.setBigDecimal(5, new BigDecimal("1.1"));
        stmt.setString(6, "varchar_a");
        stmt.setString(7, "chara");
        stmt.setInt(8, 2);
        stmt.setLong(9, 2L);
        stmt.setBigDecimal(10, new BigDecimal("2.1"));
        stmt.setString(11, "varchar_b");
        stmt.setString(12, "charb");
        stmt.setInt(13, 3);
        stmt.setLong(14, 3L);
        stmt.setBigDecimal(15, new BigDecimal("3.1"));
        stmt.setDate(16, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY));
        stmt.executeUpdate();

        stmt.setString(1, "varchar2");
        stmt.setString(2, "char2");
        stmt.setInt(3, 2);
        stmt.setLong(4, 2L);
        stmt.setBigDecimal(5, new BigDecimal("2.2"));
        stmt.setString(6, "varchar_a");
        stmt.setString(7, "chara");
        stmt.setInt(8, 3);
        stmt.setLong(9, 3L);
        stmt.setBigDecimal(10, new BigDecimal("3.2"));
        stmt.setString(11, "varchar_b");
        stmt.setString(12, "charb");
        stmt.setInt(13, 4);
        stmt.setLong(14, 4L);
        stmt.setBigDecimal(15, new BigDecimal("4.2"));
        stmt.setDate(16, date);
        stmt.executeUpdate();

        stmt.setString(1, "varchar3");
        stmt.setString(2, "char3");
        stmt.setInt(3, 3);
        stmt.setLong(4, 3L);
        stmt.setBigDecimal(5, new BigDecimal("3.3"));
        stmt.setString(6, "varchar_a");
        stmt.setString(7, "chara");
        stmt.setInt(8, 4);
        stmt.setLong(9, 4L);
        stmt.setBigDecimal(10, new BigDecimal("4.3"));
        stmt.setString(11, "varchar_b");
        stmt.setString(12, "charb");
        stmt.setInt(13, 5);
        stmt.setLong(14, 5L);
        stmt.setBigDecimal(15, new BigDecimal("5.3"));
        stmt.setDate(16, date == null ? null : new Date(date.getTime() + 2 * MILLIS_IN_DAY));
        stmt.executeUpdate();

        conn.commit();
    } finally {
        conn.close();
    }
}

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

public void testDateFormatTimeZone(String timeZoneId) throws Exception {
    Properties props = new Properties();
    props.setProperty("phoenix.query.dateFormatTimeZone", timeZoneId);
    Connection conn1 = DriverManager.getConnection(getUrl(), props);

    String tableName = generateUniqueName();
    String ddl = "CREATE TABLE IF NOT EXISTS " + tableName + " (k1 INTEGER PRIMARY KEY," + " v_date DATE,"
            + " v_time TIME," + " v_timestamp TIMESTAMP)";
    try {//  w  w  w . jav  a  2  s.co m
        conn1.createStatement().execute(ddl);

        PhoenixConnection pConn = conn1.unwrap(PhoenixConnection.class);
        verifyTimeZoneIDWithConn(pConn, PDate.INSTANCE, timeZoneId);
        verifyTimeZoneIDWithConn(pConn, PTime.INSTANCE, timeZoneId);
        verifyTimeZoneIDWithConn(pConn, PTimestamp.INSTANCE, timeZoneId);

        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(timeZoneId));
        cal.setTime(date);
        String dateStr = DateUtil.getDateFormatter(DateUtil.DEFAULT_MS_DATE_FORMAT).format(date);

        String dml = "UPSERT INTO " + tableName + " VALUES (" + "1," + "'" + dateStr + "'," + "'" + dateStr
                + "'," + "'" + dateStr + "'" + ")";
        conn1.createStatement().execute(dml);
        conn1.commit();

        PhoenixStatement stmt = conn1.createStatement().unwrap(PhoenixStatement.class);
        ResultSet rs = stmt.executeQuery("SELECT v_date, v_time, v_timestamp FROM " + tableName);

        assertTrue(rs.next());
        assertEquals(rs.getDate(1).toString(), new Date(cal.getTimeInMillis()).toString());
        assertEquals(rs.getTime(2).toString(), new Time(cal.getTimeInMillis()).toString());
        assertEquals(rs.getTimestamp(3).getTime(), cal.getTimeInMillis());
        assertFalse(rs.next());

        StatementContext stmtContext = stmt.getQueryPlan().getContext();
        verifyTimeZoneIDWithFormatter(stmtContext.getDateFormatter(), timeZoneId);
        verifyTimeZoneIDWithFormatter(stmtContext.getTimeFormatter(), timeZoneId);
        verifyTimeZoneIDWithFormatter(stmtContext.getTimestampFormatter(), timeZoneId);

        stmt.close();
    } finally {
        conn1.close();
    }
}