Example usage for java.sql Types DATE

List of usage examples for java.sql Types DATE

Introduction

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

Prototype

int DATE

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

Click Source Link

Document

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

Usage

From source file:org.apache.ddlutils.platform.mssql.MSSqlBuilder.java

/**
 * {@inheritDoc}/*from  ww  w. ja  v a 2  s . co  m*/
 */
protected String getValueAsString(Column column, Object value) {
    if (value == null) {
        return "NULL";
    }

    StringBuffer result = new StringBuffer();

    switch (column.getTypeCode()) {
    case Types.REAL:
    case Types.NUMERIC:
    case Types.FLOAT:
    case Types.DOUBLE:
    case Types.DECIMAL:
        // SQL Server does not want quotes around the value
        if (!(value instanceof String) && (getValueNumberFormat() != null)) {
            result.append(getValueNumberFormat().format(value));
        } else {
            result.append(value.toString());
        }
        break;
    case Types.DATE:
        result.append("CAST(");
        result.append(getPlatformInfo().getValueQuoteToken());
        result.append(value instanceof String ? (String) value : getValueDateFormat().format(value));
        result.append(getPlatformInfo().getValueQuoteToken());
        result.append(" AS datetime)");
        break;
    case Types.TIME:
        result.append("CAST(");
        result.append(getPlatformInfo().getValueQuoteToken());
        result.append(value instanceof String ? (String) value : getValueTimeFormat().format(value));
        result.append(getPlatformInfo().getValueQuoteToken());
        result.append(" AS datetime)");
        break;
    case Types.TIMESTAMP:
        result.append("CAST(");
        result.append(getPlatformInfo().getValueQuoteToken());
        result.append(value.toString());
        result.append(getPlatformInfo().getValueQuoteToken());
        result.append(" AS datetime)");
        break;
    }
    return super.getValueAsString(column, value);
}

From source file:co.nubetech.apache.hadoop.DateSplitter.java

/**
 * Retrieve the value from the column in a type-appropriate manner and
 * return its timestamp since the epoch. If the column is null, then return
 * Long.MIN_VALUE. This will cause a special split to be generated for the
 * NULL case, but may also cause poorly-balanced splits if most of the
 * actual dates are positive time since the epoch, etc.
 *///from  w  w  w  .  j av  a 2  s .co m
private long resultSetColToLong(ResultSet rs, int colNum, int sqlDataType) throws SQLException {
    try {
        switch (sqlDataType) {
        case Types.DATE:
            return rs.getDate(colNum).getTime();
        case Types.TIME:
            return rs.getTime(colNum).getTime();
        case Types.TIMESTAMP:
            return rs.getTimestamp(colNum).getTime();
        default:
            throw new SQLException("Not a date-type field");
        }
    } catch (NullPointerException npe) {
        // null column. return minimum long value.
        LOG.warn("Encountered a NULL date in the split column. Splits may be poorly balanced.");
        return Long.MIN_VALUE;
    }
}

From source file:com.cloudera.sqoop.mapreduce.db.DateSplitter.java

/**
    Retrieve the value from the column in a type-appropriate manner and
    return its timestamp since the epoch. If the column is null, then return
    Long.MIN_VALUE.  This will cause a special split to be generated for the
    NULL case, but may also cause poorly-balanced splits if most of the
    actual dates are positive time since the epoch, etc.
  *///  ww  w.j  a v a  2s . c om
private long resultSetColToLong(ResultSet rs, int colNum, int sqlDataType) throws SQLException {
    try {
        switch (sqlDataType) {
        case Types.DATE:
            return rs.getDate(colNum).getTime();
        case Types.TIME:
            return rs.getTime(colNum).getTime();
        case Types.TIMESTAMP:
            return rs.getTimestamp(colNum).getTime();
        default:
            throw new SQLException("Not a date-type field");
        }
    } catch (NullPointerException npe) {
        // null column. return minimum long value.
        LOG.warn("Encountered a NULL date in the split column. " + "Splits may be poorly balanced.");
        return Long.MIN_VALUE;
    }
}

From source file:org.akaza.openclinica.dao.submit.EventCRFDAO.java

public EntityBean update(EntityBean eb) {
    EventCRFBean ecb = (EventCRFBean) eb;

    ecb.setActive(false);//from  ww  w .  j  a v  a2  s .c om

    HashMap variables = new HashMap();
    HashMap nullVars = new HashMap();
    variables.put(new Integer(1), new Integer(ecb.getStudyEventId()));
    variables.put(new Integer(2), new Integer(ecb.getCRFVersionId()));
    if (ecb.getDateInterviewed() == null) {
        nullVars.put(new Integer(3), new Integer(Types.DATE));
        variables.put(new Integer(3), null);
    } else {
        variables.put(new Integer(3), ecb.getDateInterviewed());
    }
    variables.put(new Integer(4), ecb.getInterviewerName());
    variables.put(new Integer(5), new Integer(ecb.getCompletionStatusId()));
    variables.put(new Integer(6), new Integer(ecb.getStatus().getId()));
    variables.put(new Integer(7), ecb.getAnnotations());
    if (ecb.getDateCompleted() == null) {
        nullVars.put(new Integer(8), new Integer(Types.TIMESTAMP));
        variables.put(new Integer(8), null);
    } else {
        variables.put(new Integer(8), new java.sql.Timestamp(ecb.getDateCompleted().getTime()));
    }
    // variables.put(new Integer(8),ecb.getDateCompleted());

    variables.put(new Integer(9), new Integer(ecb.getValidatorId()));

    if (ecb.getDateValidate() == null) {
        nullVars.put(new Integer(10), new Integer(Types.DATE));
        variables.put(new Integer(10), null);
    } else {
        variables.put(new Integer(10), ecb.getDateValidate());
    }
    // variables.put(new Integer(10),ecb.getDateValidate());

    if (ecb.getDateValidateCompleted() == null) {
        nullVars.put(new Integer(11), new Integer(Types.TIMESTAMP));
        variables.put(new Integer(11), null);
    } else {
        variables.put(new Integer(11), new Timestamp(ecb.getDateValidateCompleted().getTime()));
    }
    // variables.put(new Integer(11),ecb.getDateValidateCompleted());
    variables.put(new Integer(12), ecb.getValidatorAnnotations());
    variables.put(new Integer(13), ecb.getValidateString());
    variables.put(new Integer(14), new Integer(ecb.getStudySubjectId()));
    variables.put(new Integer(15), new Integer(ecb.getUpdaterId()));
    variables.put(new Integer(16), new Boolean(ecb.isElectronicSignatureStatus()));

    variables.put(new Integer(17), new Boolean(ecb.isSdvStatus()));
    if (ecb.getOldStatus() != null && ecb.getOldStatus().getId() > 0) {
        variables.put(new Integer(18), new Integer(ecb.getOldStatus().getId()));
    } else {
        variables.put(new Integer(18), new Integer(0));
    }
    // @pgawade 22-May-2011 added the sdv updater id variable
    variables.put(new Integer(19), ecb.getSdvUpdateId());
    // variables.put(new Integer(19), new Integer(ecb.getId()));
    variables.put(new Integer(21), new Integer(ecb.getId()));
    variables.put(new Integer(20), new Integer(ecb.getFormLayoutId()));

    this.execute(digester.getQuery("update"), variables, nullVars);

    if (isQuerySuccessful()) {
        ecb.setActive(true);
    }

    return ecb;
}

From source file:org.apache.ddlutils.platform.oracle.Oracle8ModelReader.java

/**
  * {@inheritDoc}// w  ww  .ja  v  a  2  s .  c  o  m
  */
protected Column readColumn(DatabaseMetaDataWrapper metaData, Map values) throws SQLException {
    Column column = super.readColumn(metaData, values);

    if (column.getDefaultValue() != null) {
        // Oracle pads the default value with spaces
        column.setDefaultValue(column.getDefaultValue().trim());
    }
    if (column.getTypeCode() == Types.DECIMAL) {
        // We're back-mapping the NUMBER columns returned by Oracle
        // Note that the JDBC driver returns DECIMAL for these NUMBER columns
        switch (column.getSizeAsInt()) {
        case 1:
            if (column.getScale() == 0) {
                column.setTypeCode(Types.BIT);
            }
            break;
        case 3:
            if (column.getScale() == 0) {
                column.setTypeCode(Types.TINYINT);
            }
            break;
        case 5:
            if (column.getScale() == 0) {
                column.setTypeCode(Types.SMALLINT);
            }
            break;
        case 18:
            column.setTypeCode(Types.REAL);
            break;
        case 22:
            if (column.getScale() == 0) {
                column.setTypeCode(Types.INTEGER);
            }
            break;
        case 38:
            if (column.getScale() == 0) {
                column.setTypeCode(Types.BIGINT);
            } else {
                column.setTypeCode(Types.DOUBLE);
            }
            break;
        }
    } else if (column.getTypeCode() == Types.FLOAT) {
        // Same for REAL, FLOAT, DOUBLE PRECISION, which all back-map to FLOAT but with
        // different sizes (63 for REAL, 126 for FLOAT/DOUBLE PRECISION)
        switch (column.getSizeAsInt()) {
        case 63:
            column.setTypeCode(Types.REAL);
            break;
        case 126:
            column.setTypeCode(Types.DOUBLE);
            break;
        }
    } else if ((column.getTypeCode() == Types.DATE) || (column.getTypeCode() == Types.TIMESTAMP)) {
        // Oracle has only one DATE/TIME type, so we can't know which it is and thus map
        // it back to TIMESTAMP
        column.setTypeCode(Types.TIMESTAMP);

        // we also reverse the ISO-format adaptation, and adjust the default value to timestamp
        if (column.getDefaultValue() != null) {
            Matcher matcher = _oracleIsoTimestampPattern.matcher(column.getDefaultValue());
            Timestamp timestamp = null;

            if (matcher.matches()) {
                String timestampVal = matcher.group(1);

                timestamp = Timestamp.valueOf(timestampVal);
            } else {
                matcher = _oracleIsoDatePattern.matcher(column.getDefaultValue());
                if (matcher.matches()) {
                    String dateVal = matcher.group(1);

                    timestamp = new Timestamp(Date.valueOf(dateVal).getTime());
                } else {
                    matcher = _oracleIsoTimePattern.matcher(column.getDefaultValue());
                    if (matcher.matches()) {
                        String timeVal = matcher.group(1);

                        timestamp = new Timestamp(Time.valueOf(timeVal).getTime());
                    }
                }
            }
            if (timestamp != null) {
                column.setDefaultValue(timestamp.toString());
            }
        }
    } else if (TypeMap.isTextType(column.getTypeCode())) {
        column.setDefaultValue(unescape(column.getDefaultValue(), "'", "''"));
    }
    return column;
}

From source file:com.xpfriend.fixture.cast.temp.TypeConverter.java

private static Class<?> getJavaType(int sqltype, int precision, int scale) {
    switch (sqltype) {
    case Types.BIGINT:
        return Long.class;
    case Types.BIT:
        return Boolean.class;
    case Types.BOOLEAN:
        return Boolean.class;
    case Types.CHAR:
        return String.class;
    case Types.DECIMAL:
        return getNumericType(precision, scale);
    case Types.DOUBLE:
        return Double.class;
    case Types.FLOAT:
        return Double.class;
    case Types.INTEGER:
        return Integer.class;
    case Types.LONGVARCHAR:
        return String.class;
    case Types.NUMERIC:
        return getNumericType(precision, scale);
    case Types.REAL:
        return Float.class;
    case Types.SMALLINT:
        return Short.class;
    case Types.DATE:
        return java.sql.Timestamp.class;
    case Types.TIME:
        return java.sql.Time.class;
    case Types.TIMESTAMP:
        return java.sql.Timestamp.class;
    case Types.TINYINT:
        return Byte.class;
    case Types.VARCHAR:
        return String.class;
    case Types.BLOB:
        return byte[].class;
    case Types.LONGVARBINARY:
        return byte[].class;
    case Types.CLOB:
        return String.class;
    case Types.BINARY:
        return byte[].class;
    case Types.VARBINARY:
        return byte[].class;
    case Types.NVARCHAR:
        return String.class;
    case Types.NCHAR:
        return String.class;
    case Types.LONGNVARCHAR:
        return String.class;
    case -155://  w  w w  . j  av a2 s  . c  om
        return java.sql.Timestamp.class;
    default:
        return Object.class;
    }
}

From source file:org.apache.cayenne.dbsync.merge.MergeCase.java

private static boolean isDateTimeType(int type) {
    return type == Types.DATE || type == Types.TIME || type == Types.TIMESTAMP;
}

From source file:com.netspective.sparx.form.DialogContextUtils.java

public void populateFieldValuesFromResultSet(DialogContext dc, ResultSet rs) throws SQLException {
    if (rs.next()) {
        ResultSetMetaData rsmd = rs.getMetaData();
        int colsCount = rsmd.getColumnCount();
        DialogFieldStates fieldStates = dc.getFieldStates();
        for (int i = 1; i <= colsCount; i++) {
            String fieldName = rsmd.getColumnName(i).toLowerCase();
            DialogField.State state = fieldStates.getState(fieldName, null);
            if (state != null) {
                // for columns that are Date objects, use the object setter instead of the text setter
                // because we don't need to do unnecessary formatting/parsing
                if (rsmd.getColumnType(i) == Types.DATE)
                    state.getValue().setValue(rs.getDate(i));
                else
                    state.getValue().setTextValue(rs.getString(i));
            }/*w  ww . j  a v  a2s  . c o m*/
        }
    }
}

From source file:architecture.ee.web.logo.dao.jdbc.JdbcLogoImageDao.java

public void updateLogoImage(LogoImage logoImage, InputStream is) {

    if (logoImage.isPrimary()) {
        getExtendedJdbcTemplate().update(
                getBoundSql("ARCHITECTURE_WEB.RESET_LOGO_IMAGE_BY_OBJECT_TYPE_AND_OBJECT_ID").getSql(),
                new SqlParameterValue(Types.INTEGER, logoImage.getObjectType()),
                new SqlParameterValue(Types.NUMERIC, logoImage.getObjectId()));
    }//  w ww .  ja v  a 2  s  .c o  m

    getExtendedJdbcTemplate().update(getBoundSql("ARCHITECTURE_WEB.UPDATE_LOGO_IMAGE").getSql(),
            new SqlParameterValue(Types.NUMERIC, logoImage.getObjectType()),
            new SqlParameterValue(Types.NUMERIC, logoImage.getObjectId()),
            new SqlParameterValue(Types.NUMERIC, logoImage.isPrimary() ? 1 : 0),
            new SqlParameterValue(Types.VARCHAR, logoImage.getFilename()),
            new SqlParameterValue(Types.NUMERIC, logoImage.getImageSize()),
            new SqlParameterValue(Types.VARCHAR, logoImage.getImageContentType()),
            new SqlParameterValue(Types.DATE, logoImage.getModifiedDate()),
            new SqlParameterValue(Types.NUMERIC, logoImage.getLogoId()));
    if (is != null)
        updateImageImputStream(logoImage, is);
}