Example usage for java.sql Types TIME

List of usage examples for java.sql Types TIME

Introduction

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

Prototype

int TIME

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

Click Source Link

Document

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

Usage

From source file:com.espertech.esper.util.TestSQLTypeMapUtil.java

public void testMapping() {
    Map<Integer, Class> testData = new HashMap<Integer, Class>();
    testData.put(Types.CHAR, String.class);
    testData.put(Types.VARCHAR, String.class);
    testData.put(Types.LONGVARCHAR, String.class);
    testData.put(Types.NUMERIC, BigDecimal.class);
    testData.put(Types.DECIMAL, BigDecimal.class);
    testData.put(Types.BIT, Boolean.class);
    testData.put(Types.BOOLEAN, Boolean.class);
    testData.put(Types.TINYINT, Byte.class);
    testData.put(Types.SMALLINT, Short.class);
    testData.put(Types.INTEGER, Integer.class);
    testData.put(Types.BIGINT, Long.class);
    testData.put(Types.REAL, Float.class);
    testData.put(Types.FLOAT, Double.class);
    testData.put(Types.DOUBLE, Double.class);
    testData.put(Types.BINARY, byte[].class);
    testData.put(Types.VARBINARY, byte[].class);
    testData.put(Types.LONGVARBINARY, byte[].class);
    testData.put(Types.DATE, java.sql.Date.class);
    testData.put(Types.TIMESTAMP, java.sql.Timestamp.class);
    testData.put(Types.TIME, java.sql.Time.class);
    testData.put(Types.CLOB, java.sql.Clob.class);
    testData.put(Types.BLOB, java.sql.Blob.class);
    testData.put(Types.ARRAY, java.sql.Array.class);
    testData.put(Types.STRUCT, java.sql.Struct.class);
    testData.put(Types.REF, java.sql.Ref.class);
    testData.put(Types.DATALINK, java.net.URL.class);

    for (int type : testData.keySet()) {
        Class result = SQLTypeMapUtil.sqlTypeToClass(type, null);
        log.debug(".testMapping Mapping " + type + " to " + result.getSimpleName());
        assertEquals(testData.get(type), result);
    }//from ww w.j  a va  2  s. c  om

    assertEquals(String.class, SQLTypeMapUtil.sqlTypeToClass(Types.JAVA_OBJECT, "java.lang.String"));
    assertEquals(String.class, SQLTypeMapUtil.sqlTypeToClass(Types.DISTINCT, "java.lang.String"));
}

From source file:co.nubetech.hiho.mapreduce.lib.db.apache.OracleDataDrivenDBInputFormat.java

/**
 * @return the DBSplitter implementation to use to divide the table/query into InputSplits.
 *///from  ww w  .  j  av a 2s  .c o m
@Override
protected DBSplitter getSplitter(int sqlDataType) {
    switch (sqlDataType) {
    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
        return new OracleDateSplitter();

    default:
        return super.getSplitter(sqlDataType);
    }
}

From source file:com.redsqirl.workflow.utils.jdbc.GenericConfFile.java

public GenericConfFile(String name, Connection conn) throws SQLException {
    dictionaryName = name;//from w ww  . ja  v a2  s.  c om

    databaseMetaData = conn.getMetaData();

    typeRecognized = new LinkedHashMap<Integer, FieldType>();
    typeRecognized.put(Types.BOOLEAN, FieldType.BOOLEAN);
    typeRecognized.put(Types.DATE, FieldType.DATETIME);
    typeRecognized.put(Types.TIME, FieldType.DATETIME);
    typeRecognized.put(Types.DOUBLE, FieldType.DOUBLE);
    typeRecognized.put(Types.NUMERIC, FieldType.DOUBLE);
    typeRecognized.put(Types.DECIMAL, FieldType.DOUBLE);
    typeRecognized.put(Types.REAL, FieldType.DOUBLE);
    typeRecognized.put(Types.FLOAT, FieldType.FLOAT);
    typeRecognized.put(Types.INTEGER, FieldType.INT);
    typeRecognized.put(Types.SMALLINT, FieldType.INT);
    typeRecognized.put(Types.TINYINT, FieldType.INT);
    typeRecognized.put(Types.BIGINT, FieldType.LONG);
    typeRecognized.put(Types.VARCHAR, FieldType.STRING);
    typeRecognized.put(Types.CHAR, FieldType.STRING);
    typeRecognized.put(Types.LONGVARCHAR, FieldType.STRING);
    typeRecognized.put(Types.NVARCHAR, FieldType.STRING);
    typeRecognized.put(Types.NCHAR, FieldType.STRING);
    typeRecognized.put(Types.LONGNVARCHAR, FieldType.STRING);
    typeRecognized.put(Types.TIMESTAMP, FieldType.TIMESTAMP);

}

From source file:org.apache.ddlutils.platform.DefaultValueHelper.java

/**
 * Converts the given default value from the specified original to the target
 * jdbc type./*from  w w  w . j  av a 2  s  .  co  m*/
 * 
 * @param defaultValue     The default value
 * @param originalTypeCode The original type code
 * @param targetTypeCode   The target type code
 * @return The converted default value 
 */
public String convert(String defaultValue, int originalTypeCode, int targetTypeCode) {
    String result = defaultValue;

    if (defaultValue != null) {
        switch (originalTypeCode) {
        case Types.BIT:
        case Types.BOOLEAN:
            result = convertBoolean(defaultValue, targetTypeCode).toString();
            break;
        case Types.DATE:
            if (targetTypeCode == Types.TIMESTAMP) {
                try {
                    Date date = Date.valueOf(result);

                    return new Timestamp(date.getTime()).toString();
                } catch (IllegalArgumentException ex) {
                }
            }
            break;
        case Types.TIME:
            if (targetTypeCode == Types.TIMESTAMP) {
                try {
                    Time time = Time.valueOf(result);

                    return new Timestamp(time.getTime()).toString();
                } catch (IllegalArgumentException ex) {
                }
            }
            break;
        }
    }
    return result;
}

From source file:com.streamsets.pipeline.lib.jdbc.multithread.TableReadContext.java

private static void setParamVal(PreparedStatement ps, int paramIdx, int sqlType, String paramVal)
        throws SQLException, StageException {
    Utils.checkState(OffsetQueryUtil.SQL_TYPE_TO_FIELD_TYPE.containsKey(sqlType),
            Utils.format("Unsupported Partition Offset Type: {}", sqlType));
    //All Date/Time Types are stored as long offsets
    //Parse string to get long.
    switch (sqlType) {
    case Types.TIME:
        ps.setTime(paramIdx, new java.sql.Time(Long.valueOf(paramVal)));
        break;/* ww  w .  j a  va2s .  co m*/
    case Types.DATE:
        ps.setDate(paramIdx, new java.sql.Date(Long.valueOf(paramVal)));
        break;
    case Types.TIMESTAMP:
        Timestamp ts = TableContextUtil.getTimestampForOffsetValue(paramVal);
        ps.setTimestamp(paramIdx, ts);
        break;
    default:
        ps.setObject(paramIdx,
                Field.create(OffsetQueryUtil.SQL_TYPE_TO_FIELD_TYPE.get(sqlType), paramVal).getValue());
    }
}

From source file:com.cloudera.sqoop.hive.HiveTypes.java

/** 
 * @return true if a sql type can't be translated to a precise match
 * in Hive, and we have to cast it to something more generic.
 *///from  w ww  .j  a v  a 2s .  c  o  m
public static boolean isHiveTypeImprovised(int sqlType) {
    return sqlType == Types.DATE || sqlType == Types.TIME || sqlType == Types.TIMESTAMP
            || sqlType == Types.DECIMAL || sqlType == Types.NUMERIC;
}

From source file:RowSetModel.java

public Class getColumnClass(int column) {
    String cname;/*from www.j a  v a 2s .  c  om*/
    int type;

    try {
        ResultSetMetaData meta = rowSet.getMetaData();

        if (meta == null) {
            return null;
        }
        type = meta.getColumnType(column + 1);
    } catch (SQLException e) {
        e.printStackTrace();
        return super.getColumnClass(column);
    }
    switch (type) {
    case Types.BIT: {
        cname = "java.lang.Boolean";
        break;
    }
    case Types.TINYINT: {
        cname = "java.lang.Byte";
        break;
    }
    case Types.SMALLINT: {
        cname = "java.lang.Short";
        break;
    }
    case Types.INTEGER: {
        cname = "java.lang.Integer";
        break;
    }
    case Types.BIGINT: {
        cname = "java.lang.Long";
        break;
    }
    case Types.FLOAT:
    case Types.REAL: {
        cname = "java.lang.Float";
        break;
    }
    case Types.DOUBLE: {
        cname = "java.lang.Double";
        break;
    }
    case Types.NUMERIC: {
        cname = "java.lang.Number";
        break;
    }
    case Types.DECIMAL: {
        cname = "java.math.BigDecimal";
        break;
    }
    case Types.CHAR:
    case Types.VARCHAR:
    case Types.LONGVARCHAR: {
        cname = "java.lang.String";
        break;
    }
    case Types.DATE: {
        cname = "java.sql.Date";
        break;
    }
    case Types.TIME: {
        cname = "java.sql.Time";
        break;
    }
    case Types.TIMESTAMP: {
        cname = "java.sql.Timestamp";
        break;
    }
    case Types.BINARY:
    case Types.VARBINARY:
    case Types.LONGVARBINARY: {
        cname = "byte[]";
        break;
    }
    case Types.OTHER:
    case Types.JAVA_OBJECT: {
        cname = "java.lang.Object";
        break;
    }
    case Types.CLOB: {
        cname = "java.sql.Clob";
        break;
    }
    case Types.BLOB: {
        cname = "java.ssql.Blob";
        break;
    }
    case Types.REF: {
        cname = "java.sql.Ref";
        break;
    }
    case Types.STRUCT: {
        cname = "java.sql.Struct";
        break;
    }
    default: {
        return super.getColumnClass(column);
    }
    }
    try {
        return Class.forName(cname);
    } catch (Exception e) {
        e.printStackTrace();
        return super.getColumnClass(column);
    }
}

From source file:com.trackplus.ddl.GenericStringValueConverter.java

protected String extractColumnValue(ResultSet resultSet, int columnIdx, int jdbcType)
        throws SQLException, DDLException {
    String value = resultSet.getString(columnIdx);
    if (value != null) {
        switch (jdbcType) {
        case Types.NUMERIC:
        case Types.DECIMAL:
            break;
        case Types.BIT:
        case Types.BOOLEAN:
        case Types.TINYINT:
        case Types.SMALLINT:
        case Types.INTEGER:
        case Types.BIGINT:
        case Types.REAL:
        case Types.FLOAT:
        case Types.DOUBLE: {
            break;
        }/*from w ww . java 2  s  . co  m*/

        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.TIME:
        case Types.CLOB:
        case Types.ARRAY:
        case Types.REF: {
            value = "'" + value.replaceAll("'", "''") + "'";
            break;
        }
        case Types.DATE:
        case Types.TIMESTAMP: {
            Date d = resultSet.getDate(columnIdx);
            Calendar cal = Calendar.getInstance();
            cal.setTime(d);
            int year = cal.get(Calendar.YEAR);
            if (year < 1900) {
                throw new DDLException("Invalid date:" + d);
            } else {
                value = "'" + value + "'";
            }
            break;
        }
        case Types.BLOB:
        case Types.LONGVARBINARY: {
            Blob blobValue = resultSet.getBlob(columnIdx);
            String str = new String(Base64.encodeBase64(blobValue.getBytes(1l, (int) blobValue.length())));
            value = "'" + str + "'";
            break;
        }
        default:
            break;
        }
    }
    return value;
}

From source file:org.pentaho.reporting.engine.classic.core.modules.misc.tablemodel.TypeMapper.java

private static Class mapSQLType(final int t) {
    switch (t) {//from  w w  w . j  a v a 2s . c  o  m
    case Types.ARRAY:
        return Object[].class;
    case Types.BIGINT:
        return Long.class;
    case Types.BINARY:
        return byteArrayClass;
    case Types.BIT:
        return Boolean.class;
    case Types.BLOB:
        return Blob.class;
    case Types.BOOLEAN: // Types.BOOLEAN was not part of JDK1.2.2
        return Boolean.class;
    case Types.CHAR:
        return String.class;
    case Types.CLOB:
        return Clob.class;
    case Types.DATALINK: // Types.DATALINK was not part of JDK 1.2.2
        return URL.class;
    case Types.DATE:
        return java.sql.Date.class;
    case Types.DECIMAL:
        return java.math.BigDecimal.class;
    case Types.DISTINCT:
        return Object.class;
    case Types.DOUBLE:
        return Double.class;
    case Types.FLOAT:
        return Double.class;
    case Types.INTEGER:
        return Integer.class;
    case Types.JAVA_OBJECT:
        return Object.class;
    case Types.LONGVARBINARY:
        return byteArrayClass;
    case Types.LONGVARCHAR:
        return String.class;
    case Types.NCLOB:
        return NClob.class;
    case Types.NULL:
        return Object.class;
    case Types.NUMERIC:
        return java.math.BigDecimal.class;
    case Types.NCHAR:
    case Types.NVARCHAR:
    case Types.LONGNVARCHAR:
        return String.class;
    case Types.OTHER:
        return Object.class;
    case Types.REAL:
        return Float.class;
    case Types.REF:
        return Ref.class;
    case Types.ROWID:
        return RowId.class;
    case Types.SMALLINT:
        return Short.class;
    case Types.STRUCT:
        return Struct.class;
    case Types.SQLXML:
        return SQLXML.class;
    case Types.TIME:
        return Time.class;
    case Types.TIMESTAMP:
        return Timestamp.class;
    case Types.TINYINT:
        return Byte.class;
    case Types.VARBINARY:
        return byteArrayClass;
    case Types.VARCHAR:
        return String.class;
    default:
        return Object.class;
    }
}

From source file:au.com.ish.derbydump.derbydump.metadata.Column.java

/**
 * Get a string value for the value in this column in the datarow
 * /* w  ww.ja  va  2s .c  o m*/
 * @param dataRow The row which we are exporting
 * @return an SQL statement compliant string version of the value
 */
public String toString(ResultSet dataRow) throws SQLException {

    switch (getColumnDataType()) {
    case Types.BINARY:
    case Types.VARBINARY:
    case Types.BLOB: {
        Blob obj = dataRow.getBlob(columnName);
        return (obj == null) ? "NULL" : processBinaryData(obj);
    }

    case Types.CLOB: {
        Clob obj = dataRow.getClob(columnName);
        return (obj == null) ? "NULL" : processClobData(obj);
    }

    case Types.CHAR:
    case Types.LONGNVARCHAR:
    case Types.VARCHAR: {
        String obj = dataRow.getString(columnName);
        return (obj == null) ? "NULL" : processStringData(obj);
    }

    case Types.TIME: {
        Time obj = dataRow.getTime(columnName);
        return (obj == null) ? "NULL" : processStringData(obj.toString());
    }

    case Types.DATE: {
        Date obj = dataRow.getDate(columnName);
        return (obj == null) ? "NULL" : processStringData(obj.toString());
    }

    case Types.TIMESTAMP: {
        Timestamp obj = dataRow.getTimestamp(columnName);
        return (obj == null) ? "NULL" : processStringData(obj.toString());
    }

    case Types.SMALLINT: {
        Object obj = dataRow.getObject(columnName);
        return (obj == null) ? "NULL" : obj.toString();
    }

    case Types.BIGINT: {
        Object obj = dataRow.getObject(columnName);
        return (obj == null) ? "NULL" : obj.toString();
    }

    case Types.INTEGER: {
        Object obj = dataRow.getObject(columnName);
        return (obj == null) ? "NULL" : obj.toString();
    }

    case Types.NUMERIC:
    case Types.DECIMAL: {
        BigDecimal obj = dataRow.getBigDecimal(columnName);
        return (obj == null) ? "NULL" : String.valueOf(obj);
    }

    case Types.REAL:
    case Types.FLOAT: {
        Float obj = dataRow.getFloat(columnName);
        // dataRow.getFloat() always returns a value. only way to check the null is wasNull() method
        return (dataRow.wasNull()) ? "NULL" : String.valueOf(obj);
    }

    case Types.DOUBLE: {
        Double obj = dataRow.getDouble(columnName);
        return (dataRow.wasNull()) ? "NULL" : String.valueOf(obj);
    }

    default: {
        Object obj = dataRow.getObject(columnName);
        return (obj == null) ? "NULL" : obj.toString();
    }
    }
}