當前位置: 首頁>>代碼示例>>Java>>正文


Java Types.DECIMAL屬性代碼示例

本文整理匯總了Java中java.sql.Types.DECIMAL屬性的典型用法代碼示例。如果您正苦於以下問題:Java Types.DECIMAL屬性的具體用法?Java Types.DECIMAL怎麽用?Java Types.DECIMAL使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在java.sql.Types的用法示例。


在下文中一共展示了Types.DECIMAL屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: isSigned

/**
 * Is the column a signed number?
 * 
 * @param column
 *            the first column is 1, the second is 2...
 * 
 * @return true if so
 * 
 * @throws SQLException
 *             if a database access error occurs
 */
public boolean isSigned(int column) throws SQLException {
    Field f = getField(column);
    int sqlType = f.getSQLType();

    switch (sqlType) {
        case Types.TINYINT:
        case Types.SMALLINT:
        case Types.INTEGER:
        case Types.BIGINT:
        case Types.FLOAT:
        case Types.REAL:
        case Types.DOUBLE:
        case Types.NUMERIC:
        case Types.DECIMAL:
            return !f.isUnsigned();

        case Types.DATE:
        case Types.TIME:
        case Types.TIMESTAMP:
            return false;

        default:
            return false;
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:36,代碼來源:ResultSetMetaData.java

示例2: isDecimalType

/**
 * Checks if the SQL Type is a Decimal/Number Type
 * 
 * @param type
 *            SQL Type
 */
private static final boolean isDecimalType(int type) {
    switch (type) {
        case Types.BIT:
        case Types.TINYINT:
        case Types.SMALLINT:
        case Types.INTEGER:
        case Types.BIGINT:
        case Types.FLOAT:
        case Types.REAL:
        case Types.DOUBLE:
        case Types.NUMERIC:
        case Types.DECIMAL:
            return true;
    }

    return false;
}
 
開發者ID:rafallis,項目名稱:BibliotecaPS,代碼行數:23,代碼來源:ResultSetMetaData.java

示例3: throwRangeException

private void throwRangeException(String valueAsString, int columnIndex, int jdbcType) throws SQLException {
    String datatype = null;

    switch (jdbcType) {
        case Types.TINYINT:
            datatype = "TINYINT";
            break;
        case Types.SMALLINT:
            datatype = "SMALLINT";
            break;
        case Types.INTEGER:
            datatype = "INTEGER";
            break;
        case Types.BIGINT:
            datatype = "BIGINT";
            break;
        case Types.REAL:
            datatype = "REAL";
            break;
        case Types.FLOAT:
            datatype = "FLOAT";
            break;
        case Types.DOUBLE:
            datatype = "DOUBLE";
            break;
        case Types.DECIMAL:
            datatype = "DECIMAL";
            break;
        default:
            datatype = " (JDBC type '" + jdbcType + "')";
    }

    throw SQLError.createSQLException("'" + valueAsString + "' in column '" + columnIndex + "' is outside valid range for the datatype " + datatype + ".",
            SQLError.SQL_STATE_NUMERIC_VALUE_OUT_OF_RANGE, getExceptionInterceptor());
}
 
開發者ID:JuanJoseFJ,項目名稱:ProyectoPacientes,代碼行數:35,代碼來源:ResultSetImpl.java

示例4: isNumeric

/**
 * Check whether the given SQL type is numeric.
 * @param sqlType the SQL type to be checked
 * @return whether the type is numeric
 */
public static boolean isNumeric(int sqlType) {
	return Types.BIT == sqlType || Types.BIGINT == sqlType || Types.DECIMAL == sqlType ||
			Types.DOUBLE == sqlType || Types.FLOAT == sqlType || Types.INTEGER == sqlType ||
			Types.NUMERIC == sqlType || Types.REAL == sqlType || Types.SMALLINT == sqlType ||
			Types.TINYINT == sqlType;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:11,代碼來源:JdbcUtils.java

示例5: columnClassNames

@DataProvider(name = "columnClassNames")
private Object[][] columnClassNames() {
    return new Object[][]{
        {Types.CHAR, "java.lang.String"},
        {Types.NCHAR, "java.lang.String"},
        {Types.VARCHAR, "java.lang.String"},
        {Types.NVARCHAR, "java.lang.String"},
        {Types.LONGVARCHAR, "java.lang.String"},
        {Types.LONGNVARCHAR, "java.lang.String"},
        {Types.NUMERIC, "java.math.BigDecimal"},
        {Types.DECIMAL, "java.math.BigDecimal"},
        {Types.BIT, "java.lang.Boolean"},
        {Types.TINYINT, "java.lang.Byte"},
        {Types.SMALLINT, "java.lang.Short"},
        {Types.INTEGER, "java.lang.Integer"},
        {Types.FLOAT, "java.lang.Double"},
        {Types.DOUBLE, "java.lang.Double"},
        {Types.BINARY, "byte[]"},
        {Types.VARBINARY, "byte[]"},
        {Types.LONGVARBINARY, "byte[]"},
        {Types.DATE, "java.sql.Date"},
        {Types.TIME, "java.sql.Time"},
        {Types.TIMESTAMP, "java.sql.Timestamp"},
        {Types.CLOB, "java.sql.Clob"},
        {Types.BLOB, "java.sql.Blob"}

    };

}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:29,代碼來源:RowSetMetaDataTests.java

示例6: toHiveType

/**
 * 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;
    }
}
 
開發者ID:aliyun,項目名稱:aliyun-maxcompute-data-collectors,代碼行數:40,代碼來源:HiveTypes.java

示例7: getNativeBigDecimal

/**
 * Get the value of a column in the current row as a java.math.BigDecimal
 * object
 * 
 * @param columnIndex
 *            the first column is 1, the second is 2...
 * @param scale
 *            the number of digits to the right of the decimal
 * 
 * @return the column value; if the value is SQL NULL, null
 * 
 * @exception SQLException
 *                if a database access error occurs
 */
protected BigDecimal getNativeBigDecimal(int columnIndex, int scale) throws SQLException {
    checkColumnBounds(columnIndex);

    String stringVal = null;

    Field f = this.fields[columnIndex - 1];

    Object value = this.thisRow.getColumnValue(columnIndex - 1);

    if (value == null) {
        this.wasNullFlag = true;

        return null;
    }

    this.wasNullFlag = false;

    switch (f.getSQLType()) {
        case Types.DECIMAL:
        case Types.NUMERIC:
            stringVal = StringUtils.toAsciiString((byte[]) value);
            break;
        default:
            stringVal = getNativeString(columnIndex);
    }

    return getBigDecimalFromString(stringVal, columnIndex, scale);
}
 
開發者ID:Jugendhackt,項目名稱:OpenVertretung,代碼行數:42,代碼來源:ResultSetImpl.java

示例8: isFloatingPointNumber

@Override
public boolean isFloatingPointNumber(int index) throws SQLException {
    if (this.isBinaryEncoded) {
        switch (this.metadata[index].getSQLType()) {
            case Types.FLOAT:
            case Types.DOUBLE:
            case Types.DECIMAL:
            case Types.NUMERIC:
                return true;
            default:
                return false;
        }
    }

    findAndSeekToOffset(index);

    long length = this.rowFromServer.readFieldLength();

    if (length == Buffer.NULL_LENGTH) {
        return false;
    }

    if (length == 0) {
        return false;
    }

    int offset = this.rowFromServer.getPosition();
    byte[] buffer = this.rowFromServer.getByteBuffer();

    for (int i = 0; i < (int) length; i++) {
        char c = (char) buffer[offset + i];

        if ((c == 'e') || (c == 'E')) {
            return true;
        }
    }

    return false;
}
 
開發者ID:Jugendhackt,項目名稱:OpenVertretung,代碼行數:39,代碼來源:BufferRow.java

示例9: finagle

ColumnMetaData finagle(ColumnMetaData column) {
  switch (column.type.rep) {
  case BYTE:
  case PRIMITIVE_BYTE:
  case DOUBLE:
  case PRIMITIVE_DOUBLE:
  case FLOAT:
  case PRIMITIVE_FLOAT:
  case INTEGER:
  case PRIMITIVE_INT:
  case SHORT:
  case PRIMITIVE_SHORT:
  case LONG:
  case PRIMITIVE_LONG:
    return column.setRep(ColumnMetaData.Rep.NUMBER);
  default:
    // continue
    break;
  }
  switch (column.type.id) {
  case Types.VARBINARY:
  case Types.BINARY:
    switch (getSerializationType()) {
    case JSON:
      return column.setRep(ColumnMetaData.Rep.STRING);
    case PROTOBUF:
      return column;
    default:
      throw new IllegalStateException("Unhadled case statement");
    }
  case Types.DECIMAL:
  case Types.NUMERIC:
    return column.setRep(ColumnMetaData.Rep.NUMBER);
  default:
    return column;
  }
}
 
開發者ID:apache,項目名稱:calcite-avatica,代碼行數:37,代碼來源:AbstractService.java

示例10: jdbcTypeToClass

/**
 * Get the Java type which corresponds to given SQL type.
 * @param type SQL type
 * @return The Java type
 */
public static Class<?> jdbcTypeToClass(int type) {
	Class<?> result = Object.class;

	switch (type) {
	case Types.CHAR:
	case Types.VARCHAR:
	case Types.LONGVARCHAR:
		result = String.class;
		break;

	case Types.NUMERIC:
	case Types.DECIMAL:
		result = java.math.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:
		result = Float.class;
		break;

	case Types.DOUBLE:
		result = Double.class;
		break;

	case Types.BINARY:
	case Types.VARBINARY:
	case Types.LONGVARBINARY:
		result = byte[].class;
		break;

	case Types.DATE:
		result = java.sql.Date.class;
		break;

	case Types.TIME:
		result = java.sql.Time.class;
		break;

	case Types.TIMESTAMP:
		result = java.sql.Timestamp.class;
		break;
	default:
		break;
	}

	return result;
}
 
開發者ID:holon-platform,項目名稱:holon-datastore-jdbc,代碼行數:72,代碼來源:JdbcDatastoreUtils.java

示例11: getSqlType

@Override
public int getSqlType() {
	return Types.DECIMAL;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:4,代碼來源:DecimalTypeDescriptor.java

示例12: castValue

/**
 * For the given string representation of a value, convert it to the proper
 * object based on its sqlType 
 * @param sqlType
 * @param value
 * @return
 * @see java.sql.Types
 */
public static Object castValue(int sqlType, String value) {
    Object ret = null;
    switch (sqlType) {
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.NCHAR:
        case Types.NVARCHAR: {
            ret = value;
            break;
        }
        case Types.TINYINT:
        case Types.SMALLINT: {
            ret = Short.parseShort(value);
            break;
        }
        case Types.INTEGER: {
            ret = Integer.parseInt(value);
            break;
        }
        case Types.BIGINT: {
            ret = Long.parseLong(value);
            break;
        }
        case Types.BOOLEAN: {
            ret = Boolean.parseBoolean(value);
            break;
        }
        case Types.DECIMAL:
        case Types.DOUBLE: {
            ret = Double.parseDouble(value);
            break;
        }
        case Types.FLOAT: {
            ret = Float.parseFloat(value);
            break;
        }
        case Types.DATE:
        case Types.TIME:
        case Types.TIMESTAMP: {
            for (DateFormat f : timestamp_formats) {
                try {
                    ret = f.parse(value);
                } catch (ParseException ex) {
                    // Ignore...
                }
                if (ret != null) break;
            } // FOR
            if (ret == null) throw new RuntimeException("Failed to parse timestamp '" + value + "'");
            break;
        }
        default:
            LOG.warn("Unexpected SQL Type '" + sqlType + "' for value '" + value + "'");
    } // SWITCH
    return (ret);
}
 
開發者ID:faclc4,項目名稱:HTAPBench,代碼行數:63,代碼來源:SQLUtil.java

示例13: toJavaType

/**
 * Resolve a database-specific type to the Java type that should contain it.
 * @param sqlType     sql type
 * @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;
  }
}
 
開發者ID:aliyun,項目名稱:aliyun-maxcompute-data-collectors,代碼行數:63,代碼來源:ConnManager.java

示例14: toHCatType

/**
 * Resolve a database-specific type to HCat data type. Largely follows Sqoop's
 * hive translation.
 * @param sqlType
 *          sql type
 * @return hcat type
 */
public static String toHCatType(int sqlType) {
  switch (sqlType) {

  // Ideally TINYINT and SMALLINT should be mapped to their
  // HCat equivalents tinyint and smallint respectively
  // But the Sqoop Java type conversion has them mapped to Integer
  // Even though the referenced Java doc clearly recommends otherwise.
  // Changing this now can cause many of the sequence file usages to
  // break as value class implementations will change. So, we
  // just use the same behavior here.
    case Types.SMALLINT:
    case Types.TINYINT:
    case Types.INTEGER:
      return "int";

    case Types.VARCHAR:
      return "varchar";
    case Types.CHAR:
      return "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.FLOAT:
    case Types.REAL:
      return "float";

    case Types.NUMERIC:
    case Types.DECIMAL:
      return "decimal";

    case Types.DOUBLE:
      return "double";

    case Types.BIT:
    case Types.BOOLEAN:
      return "boolean";

    case Types.BIGINT:
      return "bigint";

    case Types.BINARY:
    case Types.VARBINARY:
    case Types.BLOB:
    case Types.LONGVARBINARY:
      return "binary";

    default:
      throw new IllegalArgumentException(
        "Cannot convert SQL type to HCatalog type " + sqlType);
  }
}
 
開發者ID:aliyun,項目名稱:aliyun-maxcompute-data-collectors,代碼行數:65,代碼來源:SqoopHCatUtilities.java

示例15: classToJdbcType

/**
 * Get the SQL type which corresponds to given Java type.
 * @param type Java type
 * @return SQL type
 */
public static int classToJdbcType(Class<?> type) {
	if (type == null) {
		return Types.NULL;
	}

	if (String.class.isAssignableFrom(type)) {
		return Types.VARCHAR;
	}

	if (TypeUtils.isBoolean(type)) {
		return Types.BOOLEAN;
	}

	if (TypeUtils.isInteger(type)) {
		return Types.INTEGER;
	}
	if (TypeUtils.isLong(type)) {
		return Types.BIGINT;
	}
	if (TypeUtils.isDouble(type) || TypeUtils.isFloat(type) || TypeUtils.isBigDecimal(type)) {
		return Types.DECIMAL;
	}
	if (TypeUtils.isShort(type)) {
		return Types.SMALLINT;
	}
	if (TypeUtils.isByte(type)) {
		return Types.TINYINT;
	}
	if (TypeUtils.isNumber(type)) {
		return Types.NUMERIC;
	}

	if (type == byte[].class) {
		return Types.BINARY;
	}

	if (TypeUtils.isDate(type) || TypeUtils.isCalendar(type) || java.sql.Date.class.isAssignableFrom(type)
			|| LocalDate.class.isAssignableFrom(type)) {
		return Types.DATE;
	}
	if (LocalTime.class.isAssignableFrom(type) || java.sql.Time.class.isAssignableFrom(type)) {
		return Types.TIME;
	}
	if (LocalDateTime.class.isAssignableFrom(type) || java.sql.Timestamp.class.isAssignableFrom(type)) {
		return Types.TIMESTAMP;
	}
	if (ZonedDateTime.class.isAssignableFrom(type)) {
		return Types.TIMESTAMP_WITH_TIMEZONE;
	}

	return Types.OTHER;
}
 
開發者ID:holon-platform,項目名稱:holon-datastore-jdbc,代碼行數:57,代碼來源:JdbcDatastoreUtils.java


注:本文中的java.sql.Types.DECIMAL屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。