Example usage for java.sql Types TIMESTAMP

List of usage examples for java.sql Types TIMESTAMP

Introduction

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

Prototype

int TIMESTAMP

To view the source code for java.sql Types TIMESTAMP.

Click Source Link

Document

The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type TIMESTAMP.

Usage

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

@Override
public void update(final Nummeraanduiding nummeraanduiding) throws DAOException {
    try {/*from   w w  w.  ja  va2  s  .c  o  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:nl.ordina.bag.etl.dao.AbstractBAGDAO.java

@Override
public void update(final Pand pand) throws DAOException {
    try {/*w w  w . j a v a 2 s .c o m*/
        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.openjpa.persistence.jdbc.AnnotationPersistenceMappingParser.java

/**
 * Parse @Temporal./*  www  .  java  2 s .  co m*/
 */
private void parseTemporal(FieldMapping fm, Temporal anno) {
    List<Column> cols = fm.getValueInfo().getColumns();
    if (!cols.isEmpty() && cols.size() != 1)
        throw new MetaDataException(_loc.get("num-cols-mismatch", fm, String.valueOf(cols.size()), "1"));
    if (cols.isEmpty()) {
        cols = Arrays.asList(new Column[] { new Column() });
        if (fm.isElementCollection()) {
            if (!fm.getElementMapping().getValueInfo().getColumns().isEmpty())
                cols = fm.getElementMapping().getValueInfo().getColumns();
            else
                fm.getElementMapping().getValueInfo().setColumns(cols);
        } else
            fm.getValueInfo().setColumns(cols);
    }

    Column col = (Column) cols.get(0);
    switch (anno.value()) {
    case DATE:
        col.setType(Types.DATE);
        break;
    case TIME:
        col.setType(Types.TIME);
        break;
    case TIMESTAMP:
        col.setType(Types.TIMESTAMP);
        break;
    }
}

From source file:org.apache.openjpa.persistence.jdbc.AnnotationPersistenceMappingParser.java

/**
 * Parse @Temporal.//from  w  ww. j  av a  2s  .c om
 */
private void parseMapKeyTemporal(FieldMapping fm, MapKeyTemporal anno) {
    List<Column> cols = fm.getKeyMapping().getValueInfo().getColumns();
    if (!cols.isEmpty() && cols.size() != 1)
        throw new MetaDataException(_loc.get("num-cols-mismatch", fm, String.valueOf(cols.size()), "1"));
    if (cols.isEmpty()) {
        cols = Arrays.asList(new Column[] { new Column() });
        fm.getKeyMapping().getValueInfo().setColumns(cols);
    }

    Column col = (Column) cols.get(0);
    switch (anno.value()) {
    case DATE:
        col.setType(Types.DATE);
        break;
    case TIME:
        col.setType(Types.TIME);
        break;
    case TIMESTAMP:
        col.setType(Types.TIMESTAMP);
        break;
    }
}

From source file:org.jumpmind.db.platform.AbstractDdlBuilder.java

/**
 * Generates the string representation of the given value.
 *
 * @param column//  w ww  . j a  v a2 s .  co m
 *            The column
 * @param value
 *            The value
 * @return The string representation
 */
protected String getValueAsString(Column column, Object value) {
    if (value == null) {
        return "NULL";
    }

    StringBuffer result = new StringBuffer();

    // TODO: Handle binary types (BINARY, VARBINARY, LONGVARBINARY, BLOB)
    switch (column.getMappedTypeCode()) {
    case Types.DATE:
        result.append(databaseInfo.getValueQuoteToken());
        if (!(value instanceof String) && (getValueDateFormat() != null)) {
            // TODO: Can the format method handle java.sql.Date properly
            // ?
            result.append(getValueDateFormat().format(value));
        } else {
            result.append(value.toString());
        }
        result.append(databaseInfo.getValueQuoteToken());
        break;
    case Types.TIME:
        result.append(databaseInfo.getValueQuoteToken());
        if (!(value instanceof String) && (getValueTimeFormat() != null)) {
            // TODO: Can the format method handle java.sql.Date properly
            // ?
            result.append(getValueTimeFormat().format(value));
        } else {
            result.append(value.toString());
        }
        result.append(databaseInfo.getValueQuoteToken());
        break;
    case Types.TIMESTAMP:
        result.append(databaseInfo.getValueQuoteToken());
        // TODO: SimpleDateFormat does not support nano seconds so we
        // would
        // need a custom date formatter for timestamps
        result.append(value.toString());
        result.append(databaseInfo.getValueQuoteToken());
        break;
    case Types.REAL:
    case Types.NUMERIC:
    case Types.FLOAT:
    case Types.DOUBLE:
    case Types.DECIMAL:
        result.append(databaseInfo.getValueQuoteToken());
        if (!(value instanceof String) && (getValueNumberFormat() != null)) {
            result.append(getValueNumberFormat().format(value));
        } else {
            result.append(value.toString());
        }
        result.append(databaseInfo.getValueQuoteToken());
        break;
    default:
        result.append(databaseInfo.getValueQuoteToken());
        result.append(escapeStringValue(value.toString()));
        result.append(databaseInfo.getValueQuoteToken());
        break;
    }
    return result.toString();
}

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

@Override
public void update(final Verblijfsobject verblijfsobject) throws DAOException {
    try {//w  w w .java2  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 = ?," + " 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, verblijfsobject.getAanduidingRecordInactief().ordinal());
                        ps.setInt(2, verblijfsobject.getOfficieel().ordinal());
                        ps.setString(3, verblijfsobject.getVerblijfsobjectGeometrie());
                        ps.setInt(4, verblijfsobject.getOppervlakteVerblijfsobject());
                        ps.setInt(5, verblijfsobject.getVerblijfsobjectStatus().ordinal());
                        if (verblijfsobject.getEinddatumTijdvakGeldigheid() == null)
                            ps.setNull(6, Types.TIMESTAMP);
                        else
                            ps.setTimestamp(6,
                                    new Timestamp(verblijfsobject.getEinddatumTijdvakGeldigheid().getTime()));
                        ps.setInt(7, verblijfsobject.getInOnderzoek().ordinal());
                        ps.setDate(8, new Date(verblijfsobject.getDocumentdatum().getTime()));
                        ps.setString(9, verblijfsobject.getDocumentnummer());
                        ps.setLong(10, verblijfsobject.getHoofdAdres());
                        ps.setLong(11, verblijfsobject.getIdentificatie());
                        ps.setLong(12, verblijfsobject.getAanduidingRecordCorrectie());
                        ps.setTimestamp(13,
                                new Timestamp(verblijfsobject.getBegindatumTijdvakGeldigheid().getTime()));
                        return ps;
                    }
                });
                deleteGebruikersdoelen(verblijfsobject);
                insertGebruikersdoelen(verblijfsobject);
                deleteNevenadressen(TypeAdresseerbaarObject.VERBLIJFSOBJECT, verblijfsobject);
                insertNevenadressen(TypeAdresseerbaarObject.VERBLIJFSOBJECT, verblijfsobject);
                deleteGerelateerdePanden(verblijfsobject);
                insertGerelateerdePanden(verblijfsobject);
            }
        });
    } catch (DataAccessException e) {
        throw new DAOException("Error updating verblijfsobject: " + verblijfsobject.getIdentificatie(), e);
    }
}

From source file:org.apache.openjpa.jdbc.sql.DBDictionary.java

/**
 * Return the preferred {@link Types} constant for the given
 * {@link JavaTypes} or {@link JavaSQLTypes} constant.
 *//*from   w w w  . ja  v  a  2s.co m*/
public int getJDBCType(int metaTypeCode, boolean lob, int precis, int scale) {
    if (lob) {
        switch (metaTypeCode) {
        case JavaTypes.STRING:
        case JavaSQLTypes.ASCII_STREAM:
        case JavaSQLTypes.CHAR_STREAM:
            return getPreferredType(Types.CLOB);
        default:
            return getPreferredType(Types.BLOB);
        }
    }

    switch (metaTypeCode) {
    case JavaTypes.BOOLEAN:
    case JavaTypes.BOOLEAN_OBJ:
        return getPreferredType(Types.BIT);
    case JavaTypes.BYTE:
    case JavaTypes.BYTE_OBJ:
        return getPreferredType(Types.TINYINT);
    case JavaTypes.CHAR:
    case JavaTypes.CHAR_OBJ:
        if (storeCharsAsNumbers)
            return getPreferredType(Types.INTEGER);
        return getPreferredType(Types.CHAR);
    case JavaTypes.DOUBLE:
    case JavaTypes.DOUBLE_OBJ:
        if (precis > 0 || scale > 0) {
            return getPreferredType(Types.NUMERIC);
        } else {
            return getPreferredType(Types.DOUBLE);
        }
    case JavaTypes.FLOAT:
    case JavaTypes.FLOAT_OBJ:
        if (precis > 0 || scale > 0) {
            return getPreferredType(Types.NUMERIC);
        } else {
            return getPreferredType(Types.REAL);
        }
    case JavaTypes.INT:
    case JavaTypes.INT_OBJ:
        return getPreferredType(Types.INTEGER);
    case JavaTypes.LONG:
    case JavaTypes.LONG_OBJ:
        return getPreferredType(Types.BIGINT);
    case JavaTypes.SHORT:
    case JavaTypes.SHORT_OBJ:
        return getPreferredType(Types.SMALLINT);
    case JavaTypes.STRING:
    case JavaTypes.LOCALE:
    case JavaSQLTypes.ASCII_STREAM:
    case JavaSQLTypes.CHAR_STREAM:
        return getPreferredType(Types.VARCHAR);
    case JavaTypes.BIGINTEGER:
        if (storeLargeNumbersAsStrings)
            return getPreferredType(Types.VARCHAR);
        return getPreferredType(Types.BIGINT);
    case JavaTypes.BIGDECIMAL:
        if (storeLargeNumbersAsStrings)
            return getPreferredType(Types.VARCHAR);
        return getPreferredType(Types.NUMERIC);
    case JavaTypes.NUMBER:
        if (storeLargeNumbersAsStrings)
            return getPreferredType(Types.VARCHAR);
        return getPreferredType(Types.NUMERIC);
    case JavaTypes.CALENDAR:
    case JavaTypes.DATE:
        return getPreferredType(Types.TIMESTAMP);
    case JavaSQLTypes.SQL_ARRAY:
        return getPreferredType(Types.ARRAY);
    case JavaSQLTypes.BINARY_STREAM:
    case JavaSQLTypes.BLOB:
    case JavaSQLTypes.BYTES:
        return getPreferredType(Types.BLOB);
    case JavaSQLTypes.CLOB:
        return getPreferredType(Types.CLOB);
    case JavaSQLTypes.SQL_DATE:
        return getPreferredType(Types.DATE);
    case JavaSQLTypes.TIME:
        return getPreferredType(Types.TIME);
    case JavaSQLTypes.TIMESTAMP:
        return getPreferredType(Types.TIMESTAMP);
    default:
        return getPreferredType(Types.BLOB);
    }
}

From source file:helma.objectmodel.db.NodeManager.java

private void setStatementValue(PreparedStatement stmt, int stmtNumber, Property p, int columnType)
        throws SQLException {
    if (p.getValue() == null) {
        stmt.setNull(stmtNumber, columnType);
    } else {//from  w w w  .j a v a 2s . co  m
        switch (columnType) {
        case Types.BIT:
        case Types.BOOLEAN:
            stmt.setBoolean(stmtNumber, p.getBooleanValue());

            break;

        case Types.TINYINT:
        case Types.BIGINT:
        case Types.SMALLINT:
        case Types.INTEGER:
            stmt.setLong(stmtNumber, p.getIntegerValue());

            break;

        case Types.REAL:
        case Types.FLOAT:
        case Types.DOUBLE:
        case Types.NUMERIC:
        case Types.DECIMAL:
            stmt.setDouble(stmtNumber, p.getFloatValue());

            break;

        case Types.LONGVARBINARY:
        case Types.VARBINARY:
        case Types.BINARY:
        case Types.BLOB:
            Object b = p.getJavaObjectValue();
            if (b instanceof byte[]) {
                byte[] buf = (byte[]) b;
                try {
                    stmt.setBytes(stmtNumber, buf);
                } catch (SQLException x) {
                    ByteArrayInputStream bout = new ByteArrayInputStream(buf);
                    stmt.setBinaryStream(stmtNumber, bout, buf.length);
                }
            } else {
                throw new SQLException(
                        "expected byte[] for binary column '" + p.getName() + "', found " + b.getClass());
            }

            break;

        case Types.LONGVARCHAR:
            try {
                stmt.setString(stmtNumber, p.getStringValue());
            } catch (SQLException x) {
                String str = p.getStringValue();
                Reader r = new StringReader(str);
                stmt.setCharacterStream(stmtNumber, r, str.length());
            }

            break;

        case Types.CLOB:
            String val = p.getStringValue();
            Reader isr = new StringReader(val);
            stmt.setCharacterStream(stmtNumber, isr, val.length());

            break;

        case Types.CHAR:
        case Types.VARCHAR:
        case Types.OTHER:
            stmt.setString(stmtNumber, p.getStringValue());

            break;

        case Types.DATE:
        case Types.TIME:
        case Types.TIMESTAMP:
            stmt.setTimestamp(stmtNumber, p.getTimestampValue());

            break;

        case Types.NULL:
            stmt.setNull(stmtNumber, 0);

            break;

        default:
            stmt.setString(stmtNumber, p.getStringValue());

            break;
        }
    }
}

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

@Override
public void update(final Ligplaats ligplaats) throws DAOException {
    try {/*from w w  w  .  j ava  2 s .c  om*/
        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_ligplaats set" + " aanduiding_record_inactief = ?,"
                                        + " officieel = ?," + " ligplaats_status = ?,"
                                        + " ligplaats_geometrie = ?," + " einddatum_tijdvak_geldigheid = ?,"
                                        + " in_onderzoek = ?," + " bron_documentdatum = ?,"
                                        + " bron_documentnummer = ?," + " bag_nummeraanduiding_id = ?"
                                        + " where bag_ligplaats_id = ?" + " and aanduiding_record_correctie = ?"
                                        + " and begindatum_tijdvak_geldigheid = ?");
                        ps.setInt(1, ligplaats.getAanduidingRecordInactief().ordinal());
                        ps.setInt(2, ligplaats.getOfficieel().ordinal());
                        ps.setInt(3, ligplaats.getLigplaatsStatus().ordinal());
                        ps.setString(4, ligplaats.getLigplaatsGeometrie());
                        if (ligplaats.getEinddatumTijdvakGeldigheid() == null)
                            ps.setNull(5, Types.TIMESTAMP);
                        else
                            ps.setTimestamp(5,
                                    new Timestamp(ligplaats.getEinddatumTijdvakGeldigheid().getTime()));
                        ps.setInt(6, ligplaats.getInOnderzoek().ordinal());
                        ps.setDate(7, new Date(ligplaats.getDocumentdatum().getTime()));
                        ps.setString(8, ligplaats.getDocumentnummer());
                        ps.setLong(9, ligplaats.getHoofdAdres());
                        ps.setLong(10, ligplaats.getIdentificatie());
                        ps.setLong(11, ligplaats.getAanduidingRecordCorrectie());
                        ps.setTimestamp(12,
                                new Timestamp(ligplaats.getBegindatumTijdvakGeldigheid().getTime()));
                        return ps;
                    }
                });
                deleteNevenadressen(TypeAdresseerbaarObject.LIGPLAATS, ligplaats);
                insertNevenadressen(TypeAdresseerbaarObject.LIGPLAATS, ligplaats);
            }
        });
    } catch (DataAccessException e) {
        throw new DAOException("Error updating ligplaats: " + ligplaats.getIdentificatie(), e);
    }
}

From source file:org.apache.openjpa.jdbc.sql.DBDictionary.java

/**
 * Returns the type name for the specific constant as defined
 * by {@link java.sql.Types}./*ww w .  ja  v a2s . com*/
 *
 * @param type the type
 * @return the name for the type
 */
public String getTypeName(int type) {
    switch (type) {
    case Types.ARRAY:
        return arrayTypeName;
    case Types.BIGINT:
        return bigintTypeName;
    case Types.BINARY:
        return binaryTypeName;
    case Types.BIT:
        return bitTypeName;
    case Types.BLOB:
        return blobTypeName;
    case Types.BOOLEAN:
        return booleanTypeName;
    case Types.CHAR:
        return charTypeName;
    case Types.CLOB:
        return clobTypeName;
    case Types.DATE:
        return dateTypeName;
    case Types.DECIMAL:
        return decimalTypeName;
    case Types.DISTINCT:
        return distinctTypeName;
    case Types.DOUBLE:
        return doubleTypeName;
    case Types.FLOAT:
        return floatTypeName;
    case Types.INTEGER:
        return integerTypeName;
    case Types.JAVA_OBJECT:
        return javaObjectTypeName;
    case Types.LONGVARBINARY:
        return longVarbinaryTypeName;
    case Types.LONGVARCHAR:
        return longVarcharTypeName;
    case Types.NULL:
        return nullTypeName;
    case Types.NUMERIC:
        return numericTypeName;
    case Types.OTHER:
        return otherTypeName;
    case Types.REAL:
        return realTypeName;
    case Types.REF:
        return refTypeName;
    case Types.SMALLINT:
        return smallintTypeName;
    case Types.STRUCT:
        return structTypeName;
    case Types.TIME:
        return timeTypeName;
    case Types.TIMESTAMP:
        return timestampTypeName;
    case Types.TINYINT:
        return tinyintTypeName;
    case Types.VARBINARY:
        return varbinaryTypeName;
    case Types.VARCHAR:
        return varcharTypeName;
    default:
        return otherTypeName;
    }
}