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.sqoop.mapreduce.db.DataDrivenDBInputFormat.java

/**
 * @return the DBSplitter implementation to use to divide the table/query
 * into InputSplits./*from w  ww  .  j  a  v  a  2  s.  c o m*/
 */
protected DBSplitter getSplitter(int sqlDataType) {
    switch (sqlDataType) {
    case Types.NUMERIC:
    case Types.DECIMAL:
        return new BigDecimalSplitter();

    case Types.BIT:
    case Types.BOOLEAN:
        return new BooleanSplitter();

    case Types.INTEGER:
    case Types.TINYINT:
    case Types.SMALLINT:
    case Types.BIGINT:
        return new IntegerSplitter();

    case Types.REAL:
    case Types.FLOAT:
    case Types.DOUBLE:
        return new FloatSplitter();

    case Types.CHAR:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
    case Types.LONGNVARCHAR:
    case Types.NVARCHAR:
    case Types.NCHAR:
        return new TextSplitter();

    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
        return new DateSplitter();

    default:
        // TODO: Support BINARY, VARBINARY, LONGVARBINARY, DISTINCT, CLOB,
        // BLOB, ARRAY, STRUCT, REF, DATALINK, and JAVA_OBJECT.
        return null;
    }
}

From source file:com.google.visualization.datasource.util.SqlDataSourceHelperTest.java

/**
 * Sets the information of the table columns: labels and types. Creates empty
 * list for the table rows as well./*from   ww w .  j  a  va  2  s. c  o  m*/
 *
 * This method is called before a test is executed.
 */
@Override
protected void setUp() {
    labels = Lists.newArrayList("ID", "Fname", "Lname", "Gender", "Salary", "IsMarried", "StartDate",
            "TimeStamp", "Time");
    // Use the JDBC type constants as defined in java.sql.Types.
    types = Lists.newArrayList(Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.CHAR, Types.INTEGER,
            Types.BOOLEAN, Types.DATE, Types.TIMESTAMP, Types.TIME);
    rows = Lists.newArrayList();
}

From source file:org.silverpeas.core.test.util.SQLRequester.java

/**
 * Lists entities by executing the specified SQL query with the given parameters.
 * @param jdbcSqlQuery the {@link JdbcSqlQuery} instance.
 * @return a {@link List} of {@link ResultLine} instances.
 * @throws SQLException if an error occurs while executing the given {@link JdbcSqlQuery}.
 *//*from w  ww .  j a v  a  2  s. co  m*/
public static List<ResultLine> list(JdbcSqlQuery jdbcSqlQuery) throws SQLException {
    final List<Pair<String, Integer>> metaData = new ArrayList<>();
    return jdbcSqlQuery.execute(row -> {
        if (metaData.isEmpty()) {
            ResultSetMetaData rowMetaData = row.getMetaData();
            for (int i = 1; i <= rowMetaData.getColumnCount(); i++) {
                metaData.add(Pair.of(rowMetaData.getColumnName(i), rowMetaData.getColumnType(i)));
            }
        }
        SQLRequester.ResultLine line = new SQLRequester.ResultLine();
        for (int i = 1; i <= metaData.size(); i++) {
            Pair<String, Integer> columnNameAndType = metaData.get(i - 1);
            String name = columnNameAndType.getLeft().toUpperCase();
            final Object value;
            int sqlType = columnNameAndType.getRight();
            switch (sqlType) {
            case Types.BIGINT:
                value = row.getLong(i);
                break;
            case Types.DECIMAL:
                value = row.getBigDecimal(i);
                break;
            case Types.INTEGER:
                value = row.getInt(i);
                break;
            case Types.TIMESTAMP:
                value = row.getTimestamp(i);
                break;
            case Types.DATE:
                value = row.getDate(i);
                break;
            case Types.BOOLEAN:
                value = row.getBoolean(i);
                break;
            default:
                value = row.getString(i);
            }
            line.set(name, value);
        }
        return line;
    });
}

From source file:org.easyrec.plugin.arm.store.dao.impl.RuleminingActionDAOMysqlImpl.java

@Override
public Integer getCutoffId(Integer tenantId, Integer actionType, Date cutoff) {

    Object[] args = { tenantId, actionType, cutoff };
    int[] argTypes = { Types.INTEGER, Types.INTEGER, Types.DATE };

    StringBuilder cutoffQuery = new StringBuilder("SELECT MIN(id) FROM ");
    cutoffQuery.append(BaseActionDAO.DEFAULT_TABLE_NAME);
    cutoffQuery.append(" WHERE ").append(BaseActionDAO.DEFAULT_TENANT_COLUMN_NAME).append("=?");
    cutoffQuery.append(" AND ").append(BaseActionDAO.DEFAULT_ACTION_TYPE_COLUMN_NAME).append("=?");
    cutoffQuery.append(" AND ").append(BaseActionDAO.DEFAULT_ACTION_TIME_COLUMN_NAME).append(">?");

    return getJdbcTemplate().queryForObject(cutoffQuery.toString(), args, argTypes, Integer.class);
}

From source file:org.apache.tika.parser.jdbc.JDBCTableReader.java

private void handleCell(ResultSetMetaData rsmd, int i, ContentHandler handler, ParseContext context)
        throws SQLException, IOException, SAXException {
    switch (rsmd.getColumnType(i)) {
    case Types.BLOB:
        handleBlob(tableName, rsmd.getColumnName(i), rows, results, i, handler, context);
        break;//from ww  w  .  j av a  2  s . c om
    case Types.CLOB:
        handleClob(tableName, rsmd.getColumnName(i), rows, results, i, handler, context);
        break;
    case Types.BOOLEAN:
        handleBoolean(results, i, handler);
        break;
    case Types.DATE:
        handleDate(results, i, handler);
        break;
    case Types.TIMESTAMP:
        handleTimeStamp(results, i, handler);
        break;
    case Types.INTEGER:
        handleInteger(results, i, handler);
        break;
    case Types.FLOAT:
        //this is necessary to handle rounding issues in presentation
        //Should we just use getString(i)?
        float f = results.getFloat(i);
        if (!results.wasNull()) {
            addAllCharacters(Float.toString(f), handler);
        }
        break;
    case Types.DOUBLE:
        double d = results.getDouble(i);
        if (!results.wasNull()) {
            addAllCharacters(Double.toString(d), handler);
        }
        break;
    default:
        String s = results.getString(i);
        if (!results.wasNull()) {
            addAllCharacters(s, handler);
        }
        break;
    }
}

From source file:org.apache.ddlutils.platform.sybase.SybasePlatform.java

/**
 * Creates a new platform instance.//from w ww.  j a va 2s  .c  om
 */
public SybasePlatform() {
    PlatformInfo info = getPlatformInfo();

    info.setMaxIdentifierLength(28);
    info.setNullAsDefaultValueRequired(true);
    info.setIdentityColumnAutomaticallyRequired(true);
    info.setMultipleIdentityColumnsSupported(false);
    info.setPrimaryKeyColumnsHaveToBeRequired(true);
    info.setCommentPrefix("/*");
    info.setCommentSuffix("*/");

    info.addNativeTypeMapping(Types.ARRAY, "IMAGE");
    // BIGINT is mapped back in the model reader
    info.addNativeTypeMapping(Types.BIGINT, "DECIMAL(19,0)");
    // we're not using the native BIT type because it is rather limited (cannot be NULL, cannot be indexed)
    info.addNativeTypeMapping(Types.BIT, "SMALLINT", Types.SMALLINT);
    info.addNativeTypeMapping(Types.BLOB, "IMAGE", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.BOOLEAN, "SMALLINT", Types.SMALLINT);
    info.addNativeTypeMapping(Types.CLOB, "TEXT", Types.LONGVARCHAR);
    info.addNativeTypeMapping(Types.DATALINK, "IMAGE", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.DATE, "DATETIME", Types.TIMESTAMP);
    info.addNativeTypeMapping(Types.DISTINCT, "IMAGE", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.DOUBLE, "DOUBLE PRECISION");
    info.addNativeTypeMapping(Types.FLOAT, "DOUBLE PRECISION", Types.DOUBLE);
    info.addNativeTypeMapping(Types.INTEGER, "INT");
    info.addNativeTypeMapping(Types.JAVA_OBJECT, "IMAGE", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.LONGVARBINARY, "IMAGE");
    info.addNativeTypeMapping(Types.LONGVARCHAR, "TEXT");
    info.addNativeTypeMapping(Types.NULL, "IMAGE", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.OTHER, "IMAGE", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.REF, "IMAGE", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.STRUCT, "IMAGE", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.TIME, "DATETIME", Types.TIMESTAMP);
    info.addNativeTypeMapping(Types.TIMESTAMP, "DATETIME", Types.TIMESTAMP);
    info.addNativeTypeMapping(Types.TINYINT, "SMALLINT", Types.SMALLINT);

    info.setDefaultSize(Types.BINARY, 254);
    info.setDefaultSize(Types.VARBINARY, 254);
    info.setDefaultSize(Types.CHAR, 254);
    info.setDefaultSize(Types.VARCHAR, 254);

    setSqlBuilder(new SybaseBuilder(this));
    setModelReader(new SybaseModelReader(this));
}

From source file:org.jumpmind.db.platform.oracle.OracleDdlReader.java

@Override
protected Integer mapUnknownJdbcTypeForColumn(Map<String, Object> values) {
    String typeName = (String) values.get("TYPE_NAME");
    if (typeName != null && typeName.startsWith("DATE")) {
        return Types.DATE;
    } else if (typeName != null && typeName.startsWith("TIMESTAMP") && !typeName.endsWith("TIME ZONE")) {
        // This is for Oracle's TIMESTAMP(9)
        return Types.TIMESTAMP;
    } else if (typeName != null && typeName.startsWith("TIMESTAMP") && typeName.endsWith("WITH TIME ZONE")) {
        return ColumnTypes.ORACLE_TIMESTAMPTZ;
    } else if (typeName != null && typeName.startsWith("TIMESTAMP")
            && typeName.endsWith("WITH LOCAL TIME ZONE")) {
        return ColumnTypes.ORACLE_TIMESTAMPLTZ;
    } else if (typeName != null && typeName.startsWith("NVARCHAR")) {
        // This is for Oracle's NVARCHAR type
        return Types.VARCHAR;
    } else if (typeName != null && typeName.startsWith("LONGNVARCHAR")) {
        return Types.LONGVARCHAR;
    } else if (typeName != null && typeName.startsWith("NCHAR")) {
        return Types.CHAR;
    } else if (typeName != null && typeName.startsWith("XML")) {
        return Types.LONGVARCHAR;
    } else if (typeName != null && typeName.endsWith("CLOB")) {
        return Types.LONGVARCHAR;
    } else if (typeName != null && typeName.startsWith("BINARY_FLOAT")) {
        return Types.FLOAT;
    } else if (typeName != null && typeName.startsWith("BINARY_DOUBLE")) {
        return Types.DOUBLE;
    } else if (typeName != null && typeName.startsWith("BFILE")) {
        return Types.VARCHAR;
    } else {/*from w w w .  j  a  v  a 2s  .co  m*/
        return super.mapUnknownJdbcTypeForColumn(values);
    }
}

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

public void addLogoImage(LogoImage logoImage, InputStream is) {
    LogoImage toUse = logoImage;/*from w  ww. ja  v  a2 s .  c  om*/
    long logoIdToUse = logoImage.getLogoId();
    if (logoIdToUse < 1) {
        logoIdToUse = getNextId(sequencerName);
        logoImage.setLogoId(logoIdToUse);
    }

    getExtendedJdbcTemplate().update(
            getBoundSql("ARCHITECTURE_WEB.RESET_LOGO_IMAGE_BY_OBJECT_TYPE_AND_OBJECT_ID").getSql(),
            new SqlParameterValue(Types.INTEGER, toUse.getObjectType()),
            new SqlParameterValue(Types.NUMERIC, toUse.getObjectId()));

    getExtendedJdbcTemplate().update(getBoundSql("ARCHITECTURE_WEB.CREATE_LOGO_IMAGE").getSql(),
            new SqlParameterValue(Types.NUMERIC, logoImage.getLogoId()),
            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.DATE, logoImage.getCreationDate()));
    updateImageImputStream(logoImage, is);
}

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

/**
 * Creates a new platform instance./*  w w  w .j  av a2 s  . c o  m*/
 */
public MSSqlPlatform() {
    PlatformInfo info = getPlatformInfo();

    info.setMaxIdentifierLength(128);
    info.setPrimaryKeyColumnAutomaticallyRequired(true);
    info.setIdentityColumnAutomaticallyRequired(true);
    info.setMultipleIdentityColumnsSupported(false);
    info.setSupportedOnUpdateActions(
            new CascadeActionEnum[] { CascadeActionEnum.CASCADE, CascadeActionEnum.NONE });
    info.addEquivalentOnUpdateActions(CascadeActionEnum.NONE, CascadeActionEnum.RESTRICT);
    info.setSupportedOnDeleteActions(
            new CascadeActionEnum[] { CascadeActionEnum.CASCADE, CascadeActionEnum.NONE });
    info.addEquivalentOnDeleteActions(CascadeActionEnum.NONE, CascadeActionEnum.RESTRICT);

    info.addNativeTypeMapping(Types.ARRAY, "IMAGE", Types.LONGVARBINARY);
    // BIGINT will be mapped back to BIGINT by the model reader 
    info.addNativeTypeMapping(Types.BIGINT, "DECIMAL(19,0)");
    info.addNativeTypeMapping(Types.BLOB, "IMAGE", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.BOOLEAN, "BIT", Types.BIT);
    info.addNativeTypeMapping(Types.CLOB, "TEXT", Types.LONGVARCHAR);
    info.addNativeTypeMapping(Types.DATALINK, "IMAGE", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.DATE, "DATETIME", Types.TIMESTAMP);
    info.addNativeTypeMapping(Types.DISTINCT, "IMAGE", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.DOUBLE, "FLOAT", Types.FLOAT);
    info.addNativeTypeMapping(Types.INTEGER, "INT");
    info.addNativeTypeMapping(Types.JAVA_OBJECT, "IMAGE", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.LONGVARBINARY, "IMAGE");
    info.addNativeTypeMapping(Types.LONGVARCHAR, "TEXT");
    info.addNativeTypeMapping(Types.NULL, "IMAGE", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.OTHER, "IMAGE", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.REF, "IMAGE", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.STRUCT, "IMAGE", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.TIME, "DATETIME", Types.TIMESTAMP);
    info.addNativeTypeMapping(Types.TIMESTAMP, "DATETIME");
    info.addNativeTypeMapping(Types.TINYINT, "SMALLINT", Types.SMALLINT);

    info.setDefaultSize(Types.CHAR, 254);
    info.setDefaultSize(Types.VARCHAR, 254);
    info.setDefaultSize(Types.BINARY, 254);
    info.setDefaultSize(Types.VARBINARY, 254);

    setSqlBuilder(new MSSqlBuilder(this));
    setModelReader(new MSSqlModelReader(this));
}

From source file:com.jk.framework.dao.dynamic.meta.Field.java

/**
 * Gets the value as float.// ww  w. j a va2s. c om
 *
 * @param defaultValue
 *            the default value
 * @return the value as float
 */
public float getValueAsFloat(final float defaultValue) {
    if (getValue() == null || getValue().trim().equals("")) {
        return defaultValue;
    }
    if (getMeta().getType() == Types.DATE || getMeta().getType() == Types.TIME) {
        final Date date = (Date) getValueObject();
        return date.getTime();
    }
    return Float.parseFloat(getValue());
}