Java Code Examples for java.sql.Types#TINYINT

The following examples show how to use java.sql.Types#TINYINT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EnumType.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private boolean isNumericType(int jdbcTypeCode) {
	switch ( jdbcTypeCode ) {
		case Types.INTEGER:
		case Types.NUMERIC:
		case Types.SMALLINT:
		case Types.TINYINT:
		case Types.BIGINT:
		case Types.DECIMAL:
		case Types.DOUBLE:
		case Types.FLOAT: {
			return true;
		}
		default:
			return false;
	}
}
 
Example 2
Source File: TypesTranslator.java    From sql-layer with GNU Affero General Public License v3.0 6 votes vote down vote up
/** Does this type represent a signed numeric type? */
public boolean isTypeSigned(TInstance type) {
    TClass tclass = TInstance.tClass(type);
    if (tclass == null)
        return false;
    switch (tclass.jdbcType()) {
    case Types.BIGINT:
    case Types.DECIMAL:
    case Types.DOUBLE:
    case Types.FLOAT:
    case Types.INTEGER:
    case Types.NUMERIC:
    case Types.REAL:
    case Types.SMALLINT:
    case Types.TINYINT:
        return true;
    default:
        return false;
    }
}
 
Example 3
Source File: DataTypeDescriptor.java    From sql-parser with Eclipse Public License 1.0 6 votes vote down vote up
public static boolean isNumericType(int jdbcType) {

        switch (jdbcType) {
        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:
        case Types.DECIMAL:
        case Types.NUMERIC:
            return true;
        default:
            return false;
        }
    }
 
Example 4
Source File: PreparedStatement.java    From Komondor with GNU General Public License v3.0 6 votes vote down vote up
public Object getObject(int parameterIndex) throws SQLException {
    checkBounds(parameterIndex, 0);

    if (this.parameterIsNull[parameterIndex - 1]) {
        return null;
    }

    // we can't rely on the default mapping for JDBC's ResultSet.getObject() for numerics, they're not one-to-one with PreparedStatement.setObject

    switch (PreparedStatement.this.parameterTypes[parameterIndex - 1]) {
        case Types.TINYINT:
            return Byte.valueOf(getByte(parameterIndex));
        case Types.SMALLINT:
            return Short.valueOf(getShort(parameterIndex));
        case Types.INTEGER:
            return Integer.valueOf(getInt(parameterIndex));
        case Types.BIGINT:
            return Long.valueOf(getLong(parameterIndex));
        case Types.FLOAT:
            return Float.valueOf(getFloat(parameterIndex));
        case Types.DOUBLE:
            return Double.valueOf(getDouble(parameterIndex));
        default:
            return this.bindingsAsRs.getObject(parameterIndex);
    }
}
 
Example 5
Source File: GrantRevokeTest.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Append a particular SQL datatype value to the given StringBuffer
 * 
 * @param sb the StringBuffer to append the value
 * @param type the java.sql.Types value to append
 */
static void appendColumnValue(StringBuffer sb, int type)
{
    switch(type)
    {
    case Types.BIGINT:
    case Types.DECIMAL:
    case Types.DOUBLE:
    case Types.FLOAT:
    case Types.INTEGER:
    case Types.NUMERIC:
    case Types.REAL:
    case Types.SMALLINT:
    case Types.TINYINT:
        sb.append("0");
        break;

    case Types.CHAR:
    case Types.VARCHAR:
        sb.append("' '");
        break;

    case Types.DATE:
        sb.append("CURRENT_DATE");
        break;

    case Types.TIME:
        sb.append("CURRENT_TIME");
        break;

    case Types.TIMESTAMP:
        sb.append("CURRENT_TIMESTAMP");
        break;

    default:
        sb.append("null");
        break;
    }
}
 
Example 6
Source File: JdbcPipelineResult.java    From Quicksql with MIT License 5 votes vote down vote up
private void fillWithDisplaySize(int[] type, int[] colCounts) {
    for (int i = 0; i < type.length; i++) {
        switch (type[i]) {
            case Types.BOOLEAN:
            case Types.TINYINT:
            case Types.SMALLINT:
                colCounts[i] = 4;
                break;
            case Types.INTEGER:
            case Types.BIGINT:
            case Types.REAL:
            case Types.FLOAT:
            case Types.DOUBLE:
                colCounts[i] = 8;
                break;
            case Types.CHAR:
            case Types.VARCHAR:
                colCounts[i] = 20;
                break;
            case Types.DATE:
            case Types.TIME:
            case Types.TIMESTAMP:
                colCounts[i] = 20;
                break;
            default:
                colCounts[i] = 20;
        }
    }
}
 
Example 7
Source File: TableEnv.java    From marble with Apache License 2.0 5 votes vote down vote up
protected SqlTypeName getSqlTypeNameForJdbcType(int jdbcType) {
  //FIX Calcite jdbc type converting bug
  SqlTypeName typeName = SqlTypeName.getNameForJdbcType(jdbcType);
  if (jdbcType == Types.LONGVARCHAR) {
    typeName = SqlTypeName.VARCHAR;
  }
  if (jdbcType == Types.SMALLINT || jdbcType == Types.TINYINT) {
    //the type of jdbc value is INTEGER when jdbcType is SMALLINT or TINYINT
    typeName = SqlTypeName.INTEGER;
  }
  return typeName;
}
 
Example 8
Source File: DataTypeUtilities.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Is the data type signed.
 * 
 * @param dtd
 *          data type descriptor
 */
public static boolean isSigned(DataTypeDescriptor dtd) {
  int typeId = dtd.getTypeId().getJDBCTypeId();

  return (typeId == Types.INTEGER || typeId == Types.FLOAT
      || typeId == Types.DECIMAL || typeId == Types.SMALLINT
      || typeId == Types.BIGINT || typeId == Types.TINYINT
      || typeId == Types.NUMERIC || typeId == Types.REAL || typeId == Types.DOUBLE);
}
 
Example 9
Source File: JsonOutputFormat.java    From sqlline with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void setJsonValue(StringBuilder sb, String value, int columnTypeId) {
  if (value == null) {
    sb.append(value);
    return;
  }
  switch (columnTypeId) {
  case Types.TINYINT:
  case Types.SMALLINT:
  case Types.INTEGER:
  case Types.BIGINT:
  case Types.REAL:
  case Types.FLOAT:
  case Types.DOUBLE:
  case Types.DECIMAL:
  case Types.NUMERIC:
  case Types.NULL:
    sb.append(value);
    return;
  case Types.BOOLEAN:
    // JSON requires true and false, not TRUE and FALSE
    sb.append(value.equalsIgnoreCase("TRUE"));
    return;
  }
  sb.append("\"");
  for (int i = 0; i < value.length(); i++) {
    if (Rows.ESCAPING_MAP.get(value.charAt(i)) != null) {
      sb.append(Rows.ESCAPING_MAP.get(value.charAt(i)));
    } else {
      sb.append(value.charAt(i));
    }
  }
  sb.append("\"");
}
 
Example 10
Source File: HiveTypes.java    From aliyun-maxcompute-data-collectors with Apache License 2.0 5 votes vote down vote up
/**
 * Given JDBC SQL types coming from another database, what is the best
 * mapping to a Hive-specific type?
 */
public static String toHiveType(int sqlType) {

    switch (sqlType) {
        case Types.INTEGER:
        case Types.SMALLINT:
            return "INT";
        case Types.VARCHAR:
        case Types.CHAR:
        case Types.LONGVARCHAR:
        case Types.NVARCHAR:
        case Types.NCHAR:
        case Types.LONGNVARCHAR:
        case Types.DATE:
        case Types.TIME:
        case Types.TIMESTAMP:
        case Types.CLOB:
            return "STRING";
        case Types.NUMERIC:
        case Types.DECIMAL:
        case Types.FLOAT:
        case Types.DOUBLE:
        case Types.REAL:
            return "DOUBLE";
        case Types.BIT:
        case Types.BOOLEAN:
            return "BOOLEAN";
        case Types.TINYINT:
            return "TINYINT";
        case Types.BIGINT:
            return "BIGINT";
        default:
      // TODO(aaron): Support BINARY, VARBINARY, LONGVARBINARY, DISTINCT,
      // BLOB, ARRAY, STRUCT, REF, JAVA_OBJECT.
      return null;
    }
}
 
Example 11
Source File: ResultSetUtil.java    From incubator-tajo with Apache License 2.0 5 votes vote down vote up
public static int tajoTypeToSqlType(TajoDataTypes.DataType type) throws SQLException {
  switch (type.getType()) {
  case BOOLEAN:
    return Types.BOOLEAN;
  case INT1:
    return Types.TINYINT;
  case INT2:
    return Types.SMALLINT;
  case INT4:
    return Types.INTEGER;
  case INT8:
    return Types.BIGINT;
  case FLOAT4:
    return Types.FLOAT;
  case FLOAT8:
    return Types.DOUBLE;
  case DECIMAL:
    return Types.DECIMAL;
  case DATE:
    return Types.TIMESTAMP;
  case VARCHAR:
    return Types.VARCHAR;
  case TEXT:
    return Types.VARCHAR;
  default:
    throw new SQLException("Unrecognized column type: " + type);
  }
}
 
Example 12
Source File: JdbcTypeUtil.java    From canal with Apache License 2.0 5 votes vote down vote up
public static Class<?> jdbcType2javaType(int jdbcType) {
    switch (jdbcType) {
        case Types.BIT:
        case Types.BOOLEAN:
            // return Boolean.class;
        case Types.TINYINT:
            return Byte.TYPE;
        case Types.SMALLINT:
            return Short.class;
        case Types.INTEGER:
            return Integer.class;
        case Types.BIGINT:
            return Long.class;
        case Types.DECIMAL:
        case Types.NUMERIC:
            return BigDecimal.class;
        case Types.REAL:
            return Float.class;
        case Types.FLOAT:
        case Types.DOUBLE:
            return Double.class;
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
            return String.class;
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
        case Types.BLOB:
            return byte[].class;
        case Types.DATE:
            return Date.class;
        case Types.TIME:
            return Time.class;
        case Types.TIMESTAMP:
            return Timestamp.class;
        default:
            return String.class;
    }
}
 
Example 13
Source File: DataDrivenDBInputFormat.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * @return the DBSplitter implementation to use to divide the table/query into InputSplits.
 */
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;
  }
}
 
Example 14
Source File: SqlTypeSide.java    From CQL with GNU Affero General Public License v3.0 4 votes vote down vote up
public static int getSqlType(String s) {
	switch (s.toLowerCase()) {
	case "varbinary":
		return Types.VARBINARY;
	case "longvarbinary":
		return Types.LONGVARBINARY;
	case "binary":
		return Types.BINARY;
	case "date":
		return Types.DATE;
	case "time":
		return Types.TIME;
	case "timestamp":
		return Types.TIMESTAMP;
	case "bigint":
		return Types.BIGINT;
	case "boolean":
		return Types.BOOLEAN;
	case "char":
		return Types.CHAR;
	case "double":
		return Types.DOUBLE;
	case "doubleprecision":
		return Types.DOUBLE;
	case "numeric":
		return Types.NUMERIC;
	case "decimal":
		return Types.DECIMAL;
	case "real":
		return Types.REAL;
	case "float":
		return Types.FLOAT;
	case "integer":
		return Types.INTEGER;
	case "tinyint":
		return Types.TINYINT;
	case "bit":
		return Types.BIT;
	case "smallint":
		return Types.SMALLINT;
	case "nvarchar":
		return Types.NVARCHAR;
	case "longvarchar":
		return Types.LONGVARCHAR;
	case "text":
		return Types.VARCHAR;
	case "varchar":
		return Types.VARCHAR;
	case "string":
		return Types.VARCHAR;
	case "blob":
		return Types.BLOB;
	case "other":
		return Types.OTHER;
	case "clob":
		return Types.CLOB;
	// case "long": return Types.Lo
	}
	// Types.
	throw new RuntimeException("Unknown sql type: " + s);
}
 
Example 15
Source File: MemsqlPOJOOutputOperator.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected void setStatementParameters(PreparedStatement statement, Object tuple) throws SQLException
{
  final int size = columnDataTypes.size();
  for (int i = 0; i < size; i++) {
    final int type = columnDataTypes.get(i);
    switch (type) {
      case (Types.CHAR):
        // TODO: verify that memsql driver handles char as int
        statement.setInt(i + 1, ((GetterChar<Object>)getters.get(i)).get(tuple));
        break;
      case (Types.VARCHAR):
        statement.setString(i + 1, ((Getter<Object, String>)getters.get(i)).get(tuple));
        break;
      case (Types.BOOLEAN):
      case (Types.TINYINT):
        statement.setBoolean(i + 1, ((GetterBoolean<Object>)getters.get(i)).get(tuple));
        break;
      case (Types.SMALLINT):
        statement.setShort(i + 1, ((GetterShort<Object>)getters.get(i)).get(tuple));
        break;
      case (Types.INTEGER):
        statement.setInt(i + 1, ((GetterInt<Object>)getters.get(i)).get(tuple));
        break;
      case (Types.BIGINT):
        statement.setLong(i + 1, ((GetterLong<Object>)getters.get(i)).get(tuple));
        break;
      case (Types.FLOAT):
        statement.setFloat(i + 1, ((GetterFloat<Object>)getters.get(i)).get(tuple));
        break;
      case (Types.DOUBLE):
        statement.setDouble(i + 1, ((GetterDouble<Object>)getters.get(i)).get(tuple));
        break;
      default:
        /*
          Types.DECIMAL
          Types.DATE
          Types.TIME
          Types.ARRAY
          Types.OTHER
         */
        statement.setObject(i + 1, ((Getter<Object, Object>)getters.get(i)).get(tuple));
        break;
    }
  }
}
 
Example 16
Source File: JdbcPOJOInputOperator.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
@Override
public void activate(Context.OperatorContext context)
{
  for (int i = 0; i < columnDataTypes.size(); i++) {
    final int type = columnDataTypes.get(i);
    JdbcPOJOInputOperator.ActiveFieldInfo activeFieldInfo = columnFieldSetters.get(i);
    switch (type) {
      case (Types.CHAR):
      case (Types.VARCHAR):
        activeFieldInfo.setterOrGetter = PojoUtils.createSetter(pojoClass,
            activeFieldInfo.fieldInfo.getPojoFieldExpression(),
          String.class);
        break;

      case (Types.BOOLEAN):
        activeFieldInfo.setterOrGetter = PojoUtils.createSetterBoolean(pojoClass,
            activeFieldInfo.fieldInfo.getPojoFieldExpression());
        break;

      case (Types.TINYINT):
        activeFieldInfo.setterOrGetter = PojoUtils.createSetterByte(pojoClass,
            activeFieldInfo.fieldInfo.getPojoFieldExpression());
        break;

      case (Types.SMALLINT):
        activeFieldInfo.setterOrGetter = PojoUtils.createSetterShort(pojoClass,
            activeFieldInfo.fieldInfo.getPojoFieldExpression());
        break;

      case (Types.INTEGER):
        activeFieldInfo.setterOrGetter = PojoUtils.createSetterInt(pojoClass,
            activeFieldInfo.fieldInfo.getPojoFieldExpression());
        break;

      case (Types.BIGINT):
        activeFieldInfo.setterOrGetter = PojoUtils.createSetterLong(pojoClass,
            activeFieldInfo.fieldInfo.getPojoFieldExpression());
        break;

      case (Types.FLOAT):
        activeFieldInfo.setterOrGetter = PojoUtils.createSetterFloat(pojoClass,
            activeFieldInfo.fieldInfo.getPojoFieldExpression());
        break;

      case (Types.DOUBLE):
        activeFieldInfo.setterOrGetter = PojoUtils.createSetterDouble(pojoClass,
            activeFieldInfo.fieldInfo.getPojoFieldExpression());
        break;

      case Types.DECIMAL:
        activeFieldInfo.setterOrGetter = PojoUtils.createSetter(pojoClass,
            activeFieldInfo.fieldInfo.getPojoFieldExpression(),
            BigDecimal.class);
        break;

      case Types.TIMESTAMP:
        activeFieldInfo.setterOrGetter = PojoUtils.createSetter(pojoClass,
            activeFieldInfo.fieldInfo.getPojoFieldExpression(),Timestamp.class);
        break;

      case Types.TIME:
        activeFieldInfo.setterOrGetter = PojoUtils.createSetter(pojoClass,
            activeFieldInfo.fieldInfo.getPojoFieldExpression(),Time.class);
        break;

      case Types.DATE:
        activeFieldInfo.setterOrGetter = PojoUtils.createSetter(pojoClass,
            activeFieldInfo.fieldInfo.getPojoFieldExpression(), Date.class);
        break;

      default:
        handleUnknownDataType(type, null, activeFieldInfo);
        break;
    }
  }
}
 
Example 17
Source File: SQLType.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private Class getClassForNumericType(Integer precision, 
        Integer scale, boolean isNullable) {
    int precValue = ((precision == null) ? -1 : precision.intValue());
    int scaleValue = ((scale == null) ? -1 : scale.intValue());

    switch (sqlType) {
        case Types.DECIMAL:
        case Types.NUMERIC:
            // some jdbc drivers put in null or zero for a numeric
            // specified without precision or scale
            // return BigInteger in that case
            if ((precValue <= 0) && (scaleValue <= 0)){
                return BigInteger.class;
            }

            if (scaleValue > 0) {
                return BigDecimal.class;
            }
            if (precValue > 18) {
                return BigInteger.class;
            }
            if (precValue > 9) {
                return (isNullable ? Long.class : Long.TYPE);
            }
            if (precValue > 4) {
                return (isNullable ? Integer.class : Integer.TYPE);
            }
            return (isNullable ? Short.class : Short.TYPE);
        case Types.FLOAT:
        case Types.DOUBLE:
        case Types.REAL:
        case Types.BIGINT:
        case Types.INTEGER:
        case Types.SMALLINT:
        case Types.TINYINT:
        case Types.BIT:
            return typeList[isNullable ? 0 : 1];
        default:
            return null;
    }
}
 
Example 18
Source File: TinyIntType.java    From requery with Apache License 2.0 4 votes vote down vote up
public TinyIntType(Class<Byte> type) {
    super(type, Types.TINYINT);
}
 
Example 19
Source File: AbstractStringRowIterator.java    From Mycat2 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Object getObject(int columnIndex) {
    int columnType = mycatRowMetaData.getColumnType(columnIndex);
    switch (columnType) {
        case Types.NUMERIC: {

        }
        case Types.DECIMAL: {
            return this.getBigDecimal(columnIndex);
        }
        case Types.BIT: {
            return this.getBoolean(columnIndex);
        }
        case Types.TINYINT: {
            return this.getByte(columnIndex);
        }
        case Types.SMALLINT: {
            return this.getShort(columnIndex);
        }
        case Types.INTEGER: {
            return this.getInt(columnIndex);
        }
        case Types.BIGINT: {
            return this.getLong(columnIndex);
        }
        case Types.REAL: {
            return this.getFloat(columnIndex);
        }
        case Types.FLOAT: {

        }
        case Types.DOUBLE: {
            return this.getDouble(columnIndex);
        }
        case Types.BINARY: {

        }
        case Types.VARBINARY: {

        }
        case Types.LONGVARBINARY: {
            return this.getBytes(columnIndex);
        }
        case Types.DATE: {
            return this.getDate(columnIndex);
        }
        case Types.TIME: {
            return this.getTime(columnIndex);
        }
        case Types.TIMESTAMP: {
            return this.getTimestamp(columnIndex);
        }
        case Types.CHAR: {

        }
        case Types.VARCHAR: {

        }
        case Types.LONGVARCHAR: {
            return this.getString(columnIndex);
        }
        case Types.BLOB: {

        }
        case Types.CLOB: {
            return this.getBytes(columnIndex);
        }
        case Types.NULL: {
            return null;
        }
        default:
            throw new RuntimeException("unsupport!");
    }
}
 
Example 20
Source File: UpdatableResultSet.java    From Komondor with GNU General Public License v3.0 4 votes vote down vote up
private void setParamValue(PreparedStatement ps, int psIdx, ResultSetRow row, int rsIdx, int sqlType) throws SQLException {
    byte[] val = row.getColumnValue(rsIdx);
    if (val == null) {
        ps.setNull(psIdx, Types.NULL);
        return;
    }
    switch (sqlType) {
        case Types.NULL:
            ps.setNull(psIdx, Types.NULL);
            break;
        case Types.TINYINT:
        case Types.SMALLINT:
        case Types.INTEGER:
            ps.setInt(psIdx, row.getInt(rsIdx));
            break;
        case Types.BIGINT:
            ps.setLong(psIdx, row.getLong(rsIdx));
            break;
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
        case Types.DECIMAL:
        case Types.NUMERIC:
            ps.setString(psIdx, row.getString(rsIdx, this.charEncoding, this.connection));
            break;
        case Types.DATE:
            ps.setDate(psIdx, row.getDateFast(rsIdx, this.connection, this, this.fastDefaultCal), this.fastDefaultCal);
            break;
        case Types.TIMESTAMP:
            ps.setTimestamp(psIdx, row.getTimestampFast(rsIdx, this.fastDefaultCal, this.connection.getDefaultTimeZone(), false, this.connection, this));
            break;
        case Types.TIME:
            ps.setTime(psIdx, row.getTimeFast(rsIdx, this.fastDefaultCal, this.connection.getDefaultTimeZone(), false, this.connection, this));
            break;
        case Types.FLOAT:
        case Types.DOUBLE:
        case Types.REAL:
        case Types.BOOLEAN:
            ps.setBytesNoEscapeNoQuotes(psIdx, val);
            break;
        /*
         * default, but also explicitly for following types:
         * case Types.BINARY:
         * case Types.BLOB:
         */
        default:
            ps.setBytes(psIdx, val);
            break;
    }

}