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.sqoop.manager.ConnManager.java

/**
 * Resolve a database-specific type to the Java type that should contain it.
 * @param sqlType     sql type/*from  ww  w  .  java 2 s. co  m*/
 * @return the name of a Java type to hold the sql datatype, or null if none.
 */
public String toJavaType(int sqlType) {
    // Mappings taken from:
    // http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html
    if (sqlType == Types.INTEGER) {
        return "Integer";
    } else if (sqlType == Types.VARCHAR) {
        return "String";
    } else if (sqlType == Types.CHAR) {
        return "String";
    } else if (sqlType == Types.LONGVARCHAR) {
        return "String";
    } else if (sqlType == Types.NVARCHAR) {
        return "String";
    } else if (sqlType == Types.NCHAR) {
        return "String";
    } else if (sqlType == Types.LONGNVARCHAR) {
        return "String";
    } else if (sqlType == Types.NUMERIC) {
        return "java.math.BigDecimal";
    } else if (sqlType == Types.DECIMAL) {
        return "java.math.BigDecimal";
    } else if (sqlType == Types.BIT) {
        return "Boolean";
    } else if (sqlType == Types.BOOLEAN) {
        return "Boolean";
    } else if (sqlType == Types.TINYINT) {
        return "Integer";
    } else if (sqlType == Types.SMALLINT) {
        return "Integer";
    } else if (sqlType == Types.BIGINT) {
        return "Long";
    } else if (sqlType == Types.REAL) {
        return "Float";
    } else if (sqlType == Types.FLOAT) {
        return "Double";
    } else if (sqlType == Types.DOUBLE) {
        return "Double";
    } else if (sqlType == Types.DATE) {
        return "java.sql.Date";
    } else if (sqlType == Types.TIME) {
        return "java.sql.Time";
    } else if (sqlType == Types.TIMESTAMP) {
        return "java.sql.Timestamp";
    } else if (sqlType == Types.BINARY || sqlType == Types.VARBINARY) {
        return BytesWritable.class.getName();
    } else if (sqlType == Types.CLOB) {
        return ClobRef.class.getName();
    } else if (sqlType == Types.BLOB || sqlType == Types.LONGVARBINARY) {
        return BlobRef.class.getName();
    } else {
        // TODO(aaron): Support DISTINCT, ARRAY, STRUCT, REF, JAVA_OBJECT.
        // Return null indicating database-specific manager should return a
        // java data type if it can find one for any nonstandard type.
        return null;
    }
}

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

public static Object wrapObject(String value, int sqlType) {
    if (null == value) {
        return null;
    }/*from w w w .jav  a  2s  .co  m*/

    switch (sqlType) {
    case Types.CHAR:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
        return value;
    case Types.NUMERIC:
    case Types.DECIMAL:
        return new BigDecimal(value);
    case Types.BIT:
        return Boolean.parseBoolean(value);
    case Types.TINYINT:
        return Byte.valueOf(value);
    case Types.SMALLINT:
        return Short.valueOf(value);
    case Types.INTEGER:
        return Integer.parseInt(value);
    case Types.BIGINT:
        return Long.parseLong(value);
    case Types.FLOAT:
        return Float.parseFloat(value);
    case Types.REAL:
    case Types.DOUBLE:
        return Double.parseDouble(value);
    case Types.BINARY:
    case Types.VARBINARY:
    case Types.LONGVARBINARY:
        return value.getBytes();
    case Types.DATE:
        return Date.valueOf(value);
    case Types.TIME:
        return Time.valueOf(value);
    case Types.TIMESTAMP:
        return Timestamp.valueOf(value);
    default:
        //do nothing
        break;

    }

    return value;
}

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

/**
  * {@inheritDoc}//from   w w w .  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.cloudera.sqoop.mapreduce.db.DataDrivenDBInputFormat.java

/**
 * @return the DBSplitter implementation to use to divide the table/query
 * into InputSplits./*ww  w  . ja  va2s .  c om*/
 */
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:
        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.db.dialect.DialectOracle.java

@Override
public JDBCInfo getJDBCTypeAndString(ColumnType type) {
    switch (type) {
    case VARCHAR:
        return jdbcInfo("NVARCHAR2(2000)", Types.VARCHAR);
    case CLOB://from   w  w  w  . ja  v  a 2  s .c o m
        return jdbcInfo("NCLOB", Types.CLOB);
    case BOOLEAN:
        return jdbcInfo("NUMBER(1,0)", Types.BIT);
    case LONG:
        return jdbcInfo("NUMBER(19,0)", Types.BIGINT);
    case DOUBLE:
        return jdbcInfo("DOUBLE PRECISION", Types.DOUBLE);
    case TIMESTAMP:
        return jdbcInfo("TIMESTAMP", Types.TIMESTAMP);
    case BLOBID:
        return jdbcInfo("VARCHAR2(40)", Types.VARCHAR);
    // -----
    case NODEID:
    case NODEIDFK:
    case NODEIDFKNP:
    case NODEIDFKMUL:
    case NODEIDFKNULL:
    case NODEVAL:
        return jdbcInfo("VARCHAR2(36)", Types.VARCHAR);
    case SYSNAME:
        return jdbcInfo("VARCHAR2(250)", Types.VARCHAR);
    case TINYINT:
        return jdbcInfo("NUMBER(3,0)", Types.TINYINT);
    case INTEGER:
        return jdbcInfo("NUMBER(10,0)", Types.INTEGER);
    case FTINDEXED:
        return jdbcInfo("CLOB", Types.CLOB);
    case FTSTORED:
        return jdbcInfo("NCLOB", Types.CLOB);
    case CLUSTERNODE:
        return jdbcInfo("NUMBER(10,0)", Types.INTEGER);
    case CLUSTERFRAGS:
        return jdbcInfo("VARCHAR2(4000)", Types.VARCHAR);
    }
    throw new AssertionError(type);
}

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

/**
 * @return the DBSplitter implementation to use to divide the table/query
 *         into InputSplits.//from  www.  j  a v  a2  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:
        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.eclipse.ecr.core.storage.sql.jdbc.dialect.DialectOracle.java

@Override
public JDBCInfo getJDBCTypeAndString(ColumnType type) {
    switch (type.spec) {
    case STRING:/*from w ww. j a  v  a 2  s  . c o  m*/
        if (type.isUnconstrained()) {
            return jdbcInfo("NVARCHAR2(2000)", Types.VARCHAR);
        } else if (type.isClob() || type.length > 2000) {
            return jdbcInfo("NCLOB", Types.CLOB);
        } else {
            return jdbcInfo("NVARCHAR2(%d)", type.length, Types.VARCHAR);
        }
    case BOOLEAN:
        return jdbcInfo("NUMBER(1,0)", Types.BIT);
    case LONG:
        return jdbcInfo("NUMBER(19,0)", Types.BIGINT);
    case DOUBLE:
        return jdbcInfo("DOUBLE PRECISION", Types.DOUBLE);
    case TIMESTAMP:
        return jdbcInfo("TIMESTAMP", Types.TIMESTAMP);
    case BLOBID:
        return jdbcInfo("VARCHAR2(40)", Types.VARCHAR);
    // -----
    case NODEID:
    case NODEIDFK:
    case NODEIDFKNP:
    case NODEIDFKMUL:
    case NODEIDFKNULL:
    case NODEIDPK:
    case NODEVAL:
        return jdbcInfo("VARCHAR2(36)", Types.VARCHAR);
    case SYSNAME:
    case SYSNAMEARRAY:
        return jdbcInfo("VARCHAR2(250)", Types.VARCHAR);
    case TINYINT:
        return jdbcInfo("NUMBER(3,0)", Types.TINYINT);
    case INTEGER:
        return jdbcInfo("NUMBER(10,0)", Types.INTEGER);
    case FTINDEXED:
        return jdbcInfo("CLOB", Types.CLOB);
    case FTSTORED:
        return jdbcInfo("NCLOB", Types.CLOB);
    case CLUSTERNODE:
        return jdbcInfo("NUMBER(10,0)", Types.INTEGER);
    case CLUSTERFRAGS:
        return jdbcInfo("VARCHAR2(4000)", Types.VARCHAR);
    }
    throw new AssertionError(type);
}

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

/**
 * @return the DBSplitter implementation to use to divide the table/query into InputSplits.
 *//*  w w  w .  ja va2s .  com*/
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:
        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.georepublic.db.utils.ResultSetConverter.java

public static StringBuffer convertCsv(ResultSet rs) throws SQLException {

    String column_name = new String();
    StringBuffer retval = new StringBuffer();
    ResultSetMetaData rsmd = rs.getMetaData();
    int numColumns = rsmd.getColumnCount();

    for (int h = 1; h < numColumns + 1; h++) {
        column_name = rsmd.getColumnName(h);

        if (h > 1) {
            retval.append(",");
        }//from   w  w w .  j  ava  2s. com

        retval.append(column_name);
    }
    retval.append("\n");

    while (rs.next()) {

        for (int i = 1; i < numColumns + 1; i++) {
            column_name = rsmd.getColumnName(i);

            if (StringUtils.equals(column_name, "the_geom")) {
                continue;
            }
            if (StringUtils.equals(column_name, "geojson")) {
                continue;
            }
            if (i > 1) {
                retval.append(",");
            }

            if (rsmd.getColumnType(i) == java.sql.Types.ARRAY) {
                retval.append(rs.getArray(column_name));
            } else if (rsmd.getColumnType(i) == java.sql.Types.BIGINT) {
                retval.append(rs.getInt(column_name));
            } else if (rsmd.getColumnType(i) == java.sql.Types.BOOLEAN) {
                retval.append(rs.getBoolean(column_name));
            } else if (rsmd.getColumnType(i) == java.sql.Types.BLOB) {
                retval.append(rs.getBlob(column_name));
            } else if (rsmd.getColumnType(i) == java.sql.Types.DOUBLE) {
                retval.append(rs.getDouble(column_name));
            } else if (rsmd.getColumnType(i) == java.sql.Types.FLOAT) {
                retval.append(rs.getFloat(column_name));
            } else if (rsmd.getColumnType(i) == java.sql.Types.INTEGER) {
                retval.append(rs.getInt(column_name));
            } else if (rsmd.getColumnType(i) == java.sql.Types.NVARCHAR) {
                retval.append(rs.getNString(column_name));
            } else if (rsmd.getColumnType(i) == java.sql.Types.VARCHAR) {
                retval.append(rs.getString(column_name));
            } else if (rsmd.getColumnType(i) == java.sql.Types.TINYINT) {
                retval.append(rs.getInt(column_name));
            } else if (rsmd.getColumnType(i) == java.sql.Types.SMALLINT) {
                retval.append(rs.getInt(column_name));
            } else if (rsmd.getColumnType(i) == java.sql.Types.DATE) {
                retval.append(rs.getDate(column_name));
            } else if (rsmd.getColumnType(i) == java.sql.Types.TIMESTAMP) {
                retval.append(rs.getTimestamp(column_name));
            } else {
                retval.append(rs.getObject(column_name));
            }

        }
        retval.append("\n");
    }

    return retval;
}

From source file:ro.nextreports.engine.querybuilder.sql.dialect.AbstractDialect.java

protected void registerDefaultJavaTypes() {
    registerJavaType(Types.BIT, Boolean.class.getName());
    registerJavaType(Types.TINYINT, Byte.class.getName());
    registerJavaType(Types.SMALLINT, Short.class.getName());
    //       registerJavaType(Types.CHAR, Character.class.getName());
    registerJavaType(Types.CHAR, String.class.getName());
    registerJavaType(Types.VARCHAR, String.class.getName());
    registerJavaType(Types.DATE, Date.class.getName());
    registerJavaType(Types.TIME, Time.class.getName());
    registerJavaType(Types.TIMESTAMP, Timestamp.class.getName());
    registerJavaType(Types.DOUBLE, Double.class.getName());
    registerJavaType(Types.FLOAT, Float.class.getName());
    registerJavaType(Types.INTEGER, Integer.class.getName());
    registerJavaType(Types.BIGINT, BigInteger.class.getName());
    //       registerJavaType(Types.BIGINT, Long.class.getName());       
    registerJavaType(Types.NUMERIC, BigDecimal.class.getName());
    registerJavaType(Types.DECIMAL, BigDecimal.class.getName());
    registerJavaType(Types.BINARY, byte[].class.getName());
    registerJavaType(Types.VARBINARY, byte[].class.getName());

    registerJavaType(Types.BLOB, String.class.getName());
    registerJavaType(Types.CLOB, String.class.getName());
    registerJavaType(Types.REAL, String.class.getName());
    registerJavaType(Types.OTHER, Object.class.getName());
}