Example usage for java.sql Types TINYINT

List of usage examples for java.sql Types TINYINT

Introduction

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

Prototype

int TINYINT

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

Click Source Link

Document

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

Usage

From source file:org.apache.kylin.jdbc.KylinClient.java

@SuppressWarnings("rawtypes")
public static Class convertType(int sqlType) {
    Class result = Object.class;

    switch (sqlType) {
    case Types.CHAR:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
        result = String.class;
        break;//from  w  w  w  . jav a  2s  . c o m
    case Types.NUMERIC:
    case Types.DECIMAL:
        result = BigDecimal.class;
        break;
    case Types.BIT:
        result = Boolean.class;
        break;
    case Types.TINYINT:
        result = Byte.class;
        break;
    case Types.SMALLINT:
        result = Short.class;
        break;
    case Types.INTEGER:
        result = Integer.class;
        break;
    case Types.BIGINT:
        result = Long.class;
        break;
    case Types.REAL:
    case Types.FLOAT:
    case Types.DOUBLE:
        result = Double.class;
        break;
    case Types.BINARY:
    case Types.VARBINARY:
    case Types.LONGVARBINARY:
        result = Byte[].class;
        break;
    case Types.DATE:
        result = Date.class;
        break;
    case Types.TIME:
        result = Time.class;
        break;
    case Types.TIMESTAMP:
        result = Timestamp.class;
        break;
    default:
        //do nothing
        break;
    }

    return result;
}

From source file:com.tesora.dve.common.TestDataGenerator.java

protected Object getColumnValue(ColumnMetadata cm) {
    Object cv = null;//ww w.  j a va 2s  . c o  m
    Calendar cal = Calendar.getInstance();

    switch (cm.getDataType()) {
    case Types.BIT:
    case Types.BOOLEAN:
        cv = Boolean.TRUE;
        break;
    case Types.BIGINT:
        cv = Long.MAX_VALUE;
        break;
    case Types.CHAR:
    case Types.VARCHAR:
        cv = StringUtils.left(baseString, cm.getSize());
        break;
    case Types.SMALLINT:
        cv = Short.MAX_VALUE;
        break;
    case Types.TINYINT:
        cv = Byte.MAX_VALUE;
        break;
    case Types.INTEGER:
        cv = Integer.MAX_VALUE;
        break;
    case Types.DOUBLE:
        cv = new Double(1234.5678); // TODO need to handle s,p
        break;
    case Types.FLOAT:
        cv = new Float(123.56); // TODO need to handle s,p
        break;
    case Types.DECIMAL:
        cv = new BigDecimal("12345.6789"); // TODO need to handle s,p
        break;
    case Types.DATE:
        cal.setTimeInMillis(123456789);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        cv = cal.getTime();
        break;
    case Types.TIMESTAMP:
        cal.setTimeInMillis(123456789);
        cv = cal.getTime();
        break;
    case Types.TIME:
        cv = new Time(123456789);
        break;
    default:
        break;
    }

    return cv;
}

From source file:org.apache.ojb.broker.metadata.FieldTypeClasses.java

/**
 * Returns a {@link FieldType} instance for the given sql type
 * (see {@link java.sql.Types}) as specified in JDBC 3.0 specification
 * (see JDBC 3.0 specification <em>Appendix B, Data Type Conversion Tables</em>).
 *
 * @param jdbcType Specify the type to look for.
 * @return A new specific {@link FieldType} instance.
 *//* w w  w.  j a  va2s. co  m*/
static FieldType newFieldType(JdbcType jdbcType) {
    FieldType result = null;
    switch (jdbcType.getType()) {
    case Types.ARRAY:
        result = new ArrayFieldType();
        break;
    case Types.BIGINT:
        result = new LongFieldType();
        break;
    case Types.BINARY:
        result = new ByteArrayFieldType();
        break;
    case Types.BIT:
        result = new BooleanFieldType();
        break;
    case Types.BLOB:
        result = new BlobFieldType();
        break;
    case Types.CHAR:
        result = new StringFieldType();
        break;
    case Types.CLOB:
        result = new ClobFieldType();
        break;
    case Types.DATE:
        result = new DateFieldType();
        break;
    case Types.DECIMAL:
        result = new BigDecimalFieldType();
        break;
    // Not needed, user have to use the underlying sql datatype in OJB mapping files
    //            case Types.DISTINCT:
    //                result = new DistinctFieldType();
    //                break;
    case Types.DOUBLE:
        result = new DoubleFieldType();
        break;
    case Types.FLOAT:
        result = new FloatFieldType();
        break;
    case Types.INTEGER:
        result = new IntegerFieldType();
        break;
    case Types.JAVA_OBJECT:
        result = new JavaObjectFieldType();
        break;
    case Types.LONGVARBINARY:
        result = new ByteArrayFieldType();
        break;
    case Types.LONGVARCHAR:
        result = new StringFieldType();
        break;
    case Types.NUMERIC:
        result = new BigDecimalFieldType();
        break;
    case Types.REAL:
        result = new FloatFieldType();
        break;
    case Types.REF:
        result = new RefFieldType();
        break;
    case Types.SMALLINT:
        result = new ShortFieldType();
        break;
    case Types.STRUCT:
        result = new StructFieldType();
        break;
    case Types.TIME:
        result = new TimeFieldType();
        break;
    case Types.TIMESTAMP:
        result = new TimestampFieldType();
        break;
    case Types.TINYINT:
        result = new ByteFieldType();
        break;
    case Types.VARBINARY:
        result = new ByteArrayFieldType();
        break;
    case Types.VARCHAR:
        result = new StringFieldType();
        break;
    case Types.OTHER:
        result = new JavaObjectFieldType();
        break;
    //
    //            case Types.NULL:
    //                result = new NullFieldType();
    //                break;

    //#ifdef JDBC30
    case Types.BOOLEAN:
        result = new BooleanFieldType();
        break;
    case Types.DATALINK:
        result = new URLFieldType();
        break;
    //#endif
    default:
        throw new OJBRuntimeException("Unkown or not supported field type specified, specified jdbc type was '"
                + jdbcType + "', as string: " + JdbcTypesHelper.getSqlTypeAsString(jdbcType.getType()));
    }
    // make sure that the sql type was set
    result.setSqlType(jdbcType);
    return result;
}

From source file:com.squid.core.jdbc.formatter.DefaultJDBCDataFormatter.java

public String formatJDBCObject(final Object jdbcObject, final int colType) throws SQLException {
    String value = "";

    switch (colType) {
    case Types.BIT:
        if (jdbcObject != null) {
            value = String.valueOf(jdbcObject);
        }/*from   w w w. j  a  v  a 2  s .  c om*/
        break;
    case Types.BOOLEAN:
        if (jdbcObject != null) {
            value = new Boolean(jdbcObject.toString()).toString();
        }
        break;
    case Types.BIGINT:
    case Types.DECIMAL:
    case Types.DOUBLE:
    case Types.FLOAT:
    case Types.REAL:
    case Types.NUMERIC:
        if (jdbcObject != null) {
            value = "" + formatter.formatDecimal(jdbcObject);
        }
        break;
    case Types.INTEGER:
    case Types.TINYINT:
    case Types.SMALLINT:
        if (jdbcObject != null) {
            value = "" + formatter.formatDecimal(jdbcObject);
        }
        break;
    case Types.CLOB:
        if (jdbcObject != null) {
            try {
                value = read((Clob) jdbcObject);
            } catch (SQLException sqle) {
                value = "";
            } catch (IOException ioe) {
                value = "";
            }
        }
        break;
    case Types.ARRAY:
        try {
            ResultSet rs = ((Array) jdbcObject).getResultSet();
            int arrayType = ((Array) jdbcObject).getBaseType();
            boolean isNotNew = false;
            while (rs.next()) {
                String current = formatJDBCObject(rs.getObject(2), arrayType);
                if ("".equals(current.trim()) == false) {
                    if (isNotNew) {
                        value = value + ",";
                    } else {
                        isNotNew = !isNotNew;
                    }
                    value = value + current;
                }
            }
            if ("".equals(value) == false) {
                value = "{" + value + "}";
            }
        } catch (SQLException sqle) {
            value = "";
        }
        break;
    case Types.JAVA_OBJECT:
        if (jdbcObject != null) {
            value = String.valueOf(jdbcObject);
        }
        break;
    case Types.DATE:
        if (jdbcObject != null) {
            value = formatter.formatDate(jdbcObject);
        }
        break;
    case Types.TIME:
        if (jdbcObject != null) {
            value = ((Time) jdbcObject).toString();
        }
        break;
    case Types.TIMESTAMP:
        if (jdbcObject != null) {
            value = formatter.formatTimestamp(jdbcObject);
        }
        break;
    case Types.LONGVARCHAR:
    case Types.VARCHAR:
    case Types.CHAR:
        if (jdbcObject != null) {
            value = jdbcObject.toString();
        } else {
            value = "NULL";
        }
        break;
    case Types.BINARY:
        value = new String((byte[]) jdbcObject);
        break;
    default:
        value = "";
    }
    if (value == null) {
        value = "";
    }
    return value;
}

From source file:org.apache.syncope.core.persistence.jpa.content.ContentLoaderHandler.java

private Object[] getParameters(final String tableName, final Attributes attrs) {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);

    Map<String, Integer> colTypes = jdbcTemplate.query("SELECT * FROM " + tableName + " WHERE 0=1",
            new ResultSetExtractor<Map<String, Integer>>() {

                @Override//from   w  w  w  .ja  v a2 s.  c om
                public Map<String, Integer> extractData(final ResultSet rs) throws SQLException {
                    Map<String, Integer> colTypes = new HashMap<>();
                    for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
                        colTypes.put(rs.getMetaData().getColumnName(i).toUpperCase(),
                                rs.getMetaData().getColumnType(i));
                    }
                    return colTypes;
                }
            });

    Object[] parameters = new Object[attrs.getLength()];
    for (int i = 0; i < attrs.getLength(); i++) {
        Integer colType = colTypes.get(attrs.getQName(i).toUpperCase());
        if (colType == null) {
            LOG.warn("No column type found for {}", attrs.getQName(i).toUpperCase());
            colType = Types.VARCHAR;
        }

        switch (colType) {
        case Types.INTEGER:
        case Types.TINYINT:
        case Types.SMALLINT:
            try {
                parameters[i] = Integer.valueOf(attrs.getValue(i));
            } catch (NumberFormatException e) {
                LOG.error("Unparsable Integer '{}'", attrs.getValue(i));
                parameters[i] = attrs.getValue(i);
            }
            break;

        case Types.NUMERIC:
        case Types.DECIMAL:
        case Types.BIGINT:
            try {
                parameters[i] = Long.valueOf(attrs.getValue(i));
            } catch (NumberFormatException e) {
                LOG.error("Unparsable Long '{}'", attrs.getValue(i));
                parameters[i] = attrs.getValue(i);
            }
            break;

        case Types.DOUBLE:
            try {
                parameters[i] = Double.valueOf(attrs.getValue(i));
            } catch (NumberFormatException e) {
                LOG.error("Unparsable Double '{}'", attrs.getValue(i));
                parameters[i] = attrs.getValue(i);
            }
            break;

        case Types.REAL:
        case Types.FLOAT:
            try {
                parameters[i] = Float.valueOf(attrs.getValue(i));
            } catch (NumberFormatException e) {
                LOG.error("Unparsable Float '{}'", attrs.getValue(i));
                parameters[i] = attrs.getValue(i);
            }
            break;

        case Types.DATE:
        case Types.TIME:
        case Types.TIMESTAMP:
            try {
                parameters[i] = FormatUtils.parseDate(attrs.getValue(i));
            } catch (ParseException e) {
                LOG.error("Unparsable Date '{}'", attrs.getValue(i));
                parameters[i] = attrs.getValue(i);
            }
            break;

        case Types.BIT:
        case Types.BOOLEAN:
            parameters[i] = "1".equals(attrs.getValue(i)) ? Boolean.TRUE : Boolean.FALSE;
            break;

        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
            try {
                parameters[i] = Hex.decodeHex(attrs.getValue(i).toCharArray());
            } catch (DecoderException | IllegalArgumentException e) {
                parameters[i] = attrs.getValue(i);
            }
            break;

        case Types.BLOB:
            try {
                parameters[i] = Hex.decodeHex(attrs.getValue(i).toCharArray());
            } catch (DecoderException | IllegalArgumentException e) {
                LOG.warn("Error decoding hex string to specify a blob parameter", e);
                parameters[i] = attrs.getValue(i);
            } catch (Exception e) {
                LOG.warn("Error creating a new blob parameter", e);
            }
            break;

        default:
            parameters[i] = attrs.getValue(i);
        }
    }

    return parameters;
}

From source file:org.apache.sqoop.mapreduce.db.DataDrivenDBInputFormat.java

/**
 * @return the DBSplitter implementation to use to divide the table/query
 * into InputSplits.//from ww  w .  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:org.nuxeo.ecm.core.storage.sql.jdbc.dialect.DialectDB2.java

@Override
public JDBCInfo getJDBCTypeAndString(ColumnType type) {
    switch (type.spec) {
    case STRING:// ww  w  .  j av  a  2 s . c  om
        if (type.isUnconstrained()) {
            return jdbcInfo("VARCHAR(255)", Types.VARCHAR);
        } else if (type.isClob() || type.length > 2000) {
            return jdbcInfo("CLOB", Types.CLOB);
        } else {
            return jdbcInfo("VARCHAR(%d)", type.length, Types.VARCHAR);
        }
    case BOOLEAN:
        return jdbcInfo("SMALLINT", Types.BIT);
    case LONG:
        return jdbcInfo("BIGINT", Types.BIGINT);
    case DOUBLE:
        return jdbcInfo("DOUBLE", Types.DOUBLE);
    case TIMESTAMP:
        return jdbcInfo("TIMESTAMP", Types.TIMESTAMP);
    case BLOBID:
        return jdbcInfo("VARCHAR(40)", Types.VARCHAR);
    // -----
    case NODEID:
    case NODEIDFK:
    case NODEIDFKNP:
    case NODEIDFKMUL:
    case NODEIDFKNULL:
    case NODEIDPK:
    case NODEVAL:
        return jdbcInfo("VARCHAR(36)", Types.VARCHAR);
    case SYSNAME:
    case SYSNAMEARRAY:
        return jdbcInfo("VARCHAR(250)", Types.VARCHAR);
    case TINYINT:
        return jdbcInfo("SMALLINT", Types.TINYINT);
    case INTEGER:
        return jdbcInfo("INTEGER", Types.INTEGER);
    case AUTOINC:
        return jdbcInfo("INTEGER", Types.INTEGER); // TODO
    case FTINDEXED:
        return jdbcInfo("CLOB", Types.CLOB);
    case FTSTORED:
        return jdbcInfo("CLOB", Types.CLOB);
    case CLUSTERNODE:
        return jdbcInfo("VARCHAR(25)", Types.VARCHAR);
    case CLUSTERFRAGS:
        return jdbcInfo("VARCHAR(4000)", Types.VARCHAR);
    default:
        throw new AssertionError(type);
    }
}

From source file:com.hangum.tadpole.engine.sql.util.RDBTypeToJavaTypeUtils.java

/**
 * ? ?/*  w  w w  . j  a  v a 2 s  .  c  om*/
 * 
 * @param sqlType
 * @return
 */
public static boolean isNumberType(int sqlType) {
    switch (sqlType) {
    case Types.BIGINT:
    case Types.DECIMAL:
    case Types.DOUBLE:
    case Types.FLOAT:
    case Types.INTEGER:
    case Types.NUMERIC:
    case Types.BIT:
    case Types.SMALLINT:
    case Types.TINYINT:
        return true;
    }

    return false;
}

From source file:org.apache.ddlutils.platform.postgresql.PostgreSqlPlatform.java

/**
 * Creates a new platform instance.//from www . j  a  v  a  2s  .c o  m
 */
public PostgreSqlPlatform() {
    PlatformInfo info = getPlatformInfo();

    info.setPrimaryKeyColumnAutomaticallyRequired(true);
    // this is the default length though it might be changed when building PostgreSQL
    // in file src/include/postgres_ext.h
    info.setMaxIdentifierLength(31);

    info.addNativeTypeMapping(Types.ARRAY, "BYTEA", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.BINARY, "BYTEA", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.BIT, "BOOLEAN");
    info.addNativeTypeMapping(Types.BLOB, "BYTEA", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.BOOLEAN, "BOOLEAN", Types.BIT);
    info.addNativeTypeMapping(Types.CLOB, "TEXT", Types.LONGVARCHAR);
    info.addNativeTypeMapping(Types.DATALINK, "BYTEA", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.DECIMAL, "NUMERIC", Types.NUMERIC);
    info.addNativeTypeMapping(Types.DISTINCT, "BYTEA", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.DOUBLE, "DOUBLE PRECISION");
    info.addNativeTypeMapping(Types.FLOAT, "DOUBLE PRECISION", Types.DOUBLE);
    info.addNativeTypeMapping(Types.JAVA_OBJECT, "BYTEA", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.LONGVARBINARY, "BYTEA");
    info.addNativeTypeMapping(Types.LONGVARCHAR, "TEXT", Types.LONGVARCHAR);
    info.addNativeTypeMapping(Types.NULL, "BYTEA", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.OTHER, "BYTEA", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.REF, "BYTEA", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.STRUCT, "BYTEA", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.TINYINT, "SMALLINT", Types.SMALLINT);
    info.addNativeTypeMapping(Types.VARBINARY, "BYTEA", Types.LONGVARBINARY);

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

    // no support for specifying the size for these types (because they are mapped
    // to BYTEA which back-maps to BLOB)
    info.setHasSize(Types.BINARY, false);
    info.setHasSize(Types.VARBINARY, false);

    setSqlBuilder(new PostgreSqlBuilder(this));
    setModelReader(new PostgreSqlModelReader(this));
}

From source file:org.apache.tajo.storage.jdbc.JdbcMetadataProviderBase.java

private TypeDesc convertDataType(ResultSet res) throws SQLException {
    final int typeId = res.getInt("DATA_TYPE");

    switch (typeId) {
    case Types.BOOLEAN:
        return new TypeDesc(newSimpleDataType(Type.BOOLEAN));

    case Types.TINYINT:
    case Types.SMALLINT:
    case Types.INTEGER:
        return new TypeDesc(newSimpleDataType(Type.INT4));

    case Types.DISTINCT: // sequence for postgresql
    case Types.BIGINT:
        return new TypeDesc(newSimpleDataType(Type.INT8));

    case Types.FLOAT:
        return new TypeDesc(newSimpleDataType(Type.FLOAT4));

    case Types.NUMERIC:
    case Types.DECIMAL:
    case Types.DOUBLE:
        return new TypeDesc(newSimpleDataType(Type.FLOAT8));

    case Types.DATE:
        return new TypeDesc(newSimpleDataType(Type.DATE));

    case Types.TIME:
        return new TypeDesc(newSimpleDataType(Type.TIME));

    case Types.TIMESTAMP:
        return new TypeDesc(newSimpleDataType(Type.TIMESTAMP));

    case Types.CHAR:
    case Types.NCHAR:
    case Types.VARCHAR:
    case Types.NVARCHAR:
    case Types.CLOB:
    case Types.NCLOB:
    case Types.LONGVARCHAR:
    case Types.LONGNVARCHAR:
        return new TypeDesc(newSimpleDataType(Type.TEXT));

    case Types.BINARY:
    case Types.VARBINARY:
    case Types.BLOB:
        return new TypeDesc(newSimpleDataType(Type.BLOB));

    default:/*w ww.j  a  v  a 2 s .  c om*/
        throw SQLExceptionUtil.toSQLException(new UnsupportedDataTypeException(typeId + ""));
    }
}