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:org.apache.ddlutils.platform.mssql.MSSqlBuilder.java

/**
 * {@inheritDoc}//from   w  w  w.  jav a2 s.  c om
 */
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: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.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://from www.j  a v  a  2 s.c  o m
        return java.sql.Timestamp.class;
    default:
        return Object.class;
    }
}

From source file:org.batoo.jpa.jdbc.adapter.HsqlAdaptor.java

/**
 * {@inheritDoc}//from   w  ww  . jav a 2  s  .c om
 * 
 */
@Override
protected String getColumnType(AbstractColumn cd, int sqlType) {
    switch (sqlType) {
    case Types.BLOB:
    case Types.CLOB:
        return "VARBINARY(" + cd.getLength() + ")";
    case Types.VARCHAR:
        return "VARCHAR(" + cd.getLength() + ")";
    case Types.TIME:
        return "TIME";
    case Types.DATE:
        return "DATE";
    case Types.TIMESTAMP:
        return "TIMESTAMP";
    case Types.CHAR:
        return "CHAR";
    case Types.BOOLEAN:
        return "BOOLEAN";
    case Types.TINYINT:
    case Types.SMALLINT:
        return "SMALLINT";
    case Types.INTEGER:
        return "INTEGER";
    case Types.BIGINT:
        return "BIGINT";
    case Types.FLOAT:
        return "FLOAT" + (cd.getPrecision() > 0 ? "(" + cd.getPrecision() + ")" : "");
    case Types.DOUBLE:
        return "DOUBLE" + (cd.getPrecision() > 0 ? "(" + cd.getPrecision() + ")" : "");
    case Types.DECIMAL:
        return "DECIMAL" + (cd.getPrecision() > 0
                ? "(" + cd.getPrecision() + (cd.getScale() > 0 ? "," + cd.getScale() : "") + ")"
                : "");
    }

    throw new IllegalArgumentException("Unhandled sql type: " + sqlType);
}

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

/** Parse the long-valued timestamp into the appropriate SQL date type. */
private Date longToDate(long val, int sqlDataType) {
    switch (sqlDataType) {
    case Types.DATE:
        return new java.sql.Date(val);
    case Types.TIME:
        return new java.sql.Time(val);
    case Types.TIMESTAMP:
        return new java.sql.Timestamp(val);
    default: // Shouldn't ever hit this case.
        return null;
    }/*ww  w.j  av a 2s  .  c o m*/
}

From source file:com.opencsv.ResultSetHelperService.java

private String getColumnValue(ResultSet rs, int colType, int colIndex, boolean trim, String dateFormatString,
        String timestampFormatString) throws SQLException, IOException {

    String value = "";

    switch (colType) {
    case Types.BIT:
    case Types.JAVA_OBJECT:
        // Once Java 7 is the minimum supported version.
        //            value = Objects.toString(rs.getObject(colIndex), "");
        value = ObjectUtils.toString(rs.getObject(colIndex), "");
        break;/*from  ww  w  . jav a 2s. c  om*/
    case Types.BOOLEAN:
        // Once Java 7 is the minimum supported version.
        //            value = Objects.toString(rs.getBoolean(colIndex));
        value = ObjectUtils.toString(rs.getBoolean(colIndex));
        break;
    case Types.NCLOB: // todo : use rs.getNClob
    case Types.CLOB:
        Clob c = rs.getClob(colIndex);
        if (c != null) {
            StrBuilder sb = new StrBuilder();
            sb.readFrom(c.getCharacterStream());
            value = sb.toString();
        }
        break;
    case Types.BIGINT:
        // Once Java 7 is the minimum supported version.
        //            value = Objects.toString(rs.getLong(colIndex));
        value = ObjectUtils.toString(rs.getLong(colIndex));
        break;
    case Types.DECIMAL:
    case Types.REAL:
    case Types.NUMERIC:
        // Once Java 7 is the minimum supported version.
        //            value = Objects.toString(rs.getBigDecimal(colIndex), "");
        value = ObjectUtils.toString(rs.getBigDecimal(colIndex), "");
        break;
    case Types.DOUBLE:
        // Once Java 7 is the minimum supported version.
        //            value = Objects.toString(rs.getDouble(colIndex));
        value = ObjectUtils.toString(rs.getDouble(colIndex));
        break;
    case Types.FLOAT:
        // Once Java 7 is the minimum supported version.
        //            value = Objects.toString(rs.getFloat(colIndex));
        value = ObjectUtils.toString(rs.getFloat(colIndex));
        break;
    case Types.INTEGER:
    case Types.TINYINT:
    case Types.SMALLINT:
        // Once Java 7 is the minimum supported version.
        //            value = Objects.toString(rs.getInt(colIndex));
        value = ObjectUtils.toString(rs.getInt(colIndex));
        break;
    case Types.DATE:
        java.sql.Date date = rs.getDate(colIndex);
        if (date != null) {
            SimpleDateFormat df = new SimpleDateFormat(dateFormatString);
            value = df.format(date);
        }
        break;
    case Types.TIME:
        // Once Java 7 is the minimum supported version.
        //            value = Objects.toString(rs.getTime(colIndex), "");
        value = ObjectUtils.toString(rs.getTime(colIndex), "");
        break;
    case Types.TIMESTAMP:
        value = handleTimestamp(rs.getTimestamp(colIndex), timestampFormatString);
        break;
    case Types.NVARCHAR: // todo : use rs.getNString
    case Types.NCHAR: // todo : use rs.getNString
    case Types.LONGNVARCHAR: // todo : use rs.getNString
    case Types.LONGVARCHAR:
    case Types.VARCHAR:
    case Types.CHAR:
        String columnValue = rs.getString(colIndex);
        if (trim && columnValue != null) {
            value = columnValue.trim();
        } else {
            value = columnValue;
        }
        break;
    default:
        value = "";
    }

    if (rs.wasNull() || value == null) {
        value = "";
    }

    return value;
}

From source file:org.executequery.gui.browser.ColumnData.java

/**
 * Returns whether this column is a date type or 
 * extension of.//from   w ww.j av  a2s .  co  m
 *
 * ie. Types.DATE, Types.TIME, Types.TIMESTAMP.
 *
 * @return true | false
 */
public boolean isDateDataType() {
    return sqlType == Types.DATE || sqlType == Types.TIME || sqlType == Types.TIMESTAMP;
}

From source file:org.apache.sqoop.manager.ConnManager.java

/**
 * Resolve a database-specific type to Avro data type.
 * @param sqlType     sql type/* ww  w.  ja v a 2 s.  co m*/
 * @return            avro type
 */
public Type toAvroType(int sqlType) {
    switch (sqlType) {
    case Types.TINYINT:
    case Types.SMALLINT:
    case Types.INTEGER:
        return Type.INT;
    case Types.BIGINT:
        return Type.LONG;
    case Types.BIT:
    case Types.BOOLEAN:
        return Type.BOOLEAN;
    case Types.REAL:
        return Type.FLOAT;
    case Types.FLOAT:
    case Types.DOUBLE:
        return Type.DOUBLE;
    case Types.NUMERIC:
    case Types.DECIMAL:
        return Type.STRING;
    case Types.CHAR:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
    case Types.LONGNVARCHAR:
    case Types.NVARCHAR:
    case Types.NCHAR:
        return Type.STRING;
    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
        return Type.STRING;
    case Types.BLOB:
    case Types.BINARY:
    case Types.VARBINARY:
    case Types.LONGVARBINARY:
        return Type.BYTES;
    default:
        throw new IllegalArgumentException("Cannot convert SQL type " + sqlType);
    }
}

From source file:org.apache.openjpa.jdbc.schema.Schemas.java

/**
 * Return the java type for the given SQL type from {@link Types}.
 *///from  w w  w  .j av a2 s. com
public static Class<?> getJavaType(int type, int size, int decimals) {
    switch (type) {
    case Types.CHAR:
        if (size == 1)
            return char.class;
        // no break
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
    case Types.CLOB:
        return String.class;
    case Types.BIT:
        return boolean.class;
    case Types.TINYINT:
        return byte.class;
    case Types.SMALLINT:
        return short.class;
    case Types.INTEGER:
        return int.class;
    case Types.BIGINT:
        return long.class;
    case Types.REAL:
    case Types.FLOAT:
        return float.class;
    case Types.DOUBLE:
    case Types.NUMERIC:
        return double.class;
    case Types.DECIMAL:
        // oracle uses this for everything, so look at size and decimals
        if (decimals == 0 && size < 10)
            return int.class;
        else if (decimals == 0)
            return long.class;
        return double.class;
    // ### return a BigDecimal if the size if out of double range?
    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
        return Date.class;
    default:
        return Object.class;
    }
}