本文整理匯總了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;
}
}
示例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;
}
示例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());
}
示例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;
}
示例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"}
};
}
示例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;
}
}
示例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);
}
示例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;
}
示例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;
}
}
示例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;
}
示例11: getSqlType
@Override
public int getSqlType() {
return Types.DECIMAL;
}
示例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);
}
示例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;
}
}
示例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);
}
}
示例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;
}