Example usage for java.sql Types DECIMAL

List of usage examples for java.sql Types DECIMAL

Introduction

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

Prototype

int DECIMAL

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

Click Source Link

Document

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

Usage

From source file:org.apache.sqoop.hive.HiveTypesORC.java

/**
 * Given JDBC SQL types coming from another database, what is the best
 * mapping to a Hive-specific type?// www  .j a  v a2 s  . c  o  m
 */
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.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";
    case Types.DECIMAL:
        return "DECIMAL";
    default:
        // TODO(aaron): Support BINARY, VARBINARY, LONGVARBINARY, DISTINCT,
        // BLOB, ARRAY, STRUCT, REF, JAVA_OBJECT.
        return null;
    }
}

From source file:com.espertech.esper.util.TestSQLTypeMapUtil.java

public void testMapping() {
    Map<Integer, Class> testData = new HashMap<Integer, Class>();
    testData.put(Types.CHAR, String.class);
    testData.put(Types.VARCHAR, String.class);
    testData.put(Types.LONGVARCHAR, String.class);
    testData.put(Types.NUMERIC, BigDecimal.class);
    testData.put(Types.DECIMAL, BigDecimal.class);
    testData.put(Types.BIT, Boolean.class);
    testData.put(Types.BOOLEAN, Boolean.class);
    testData.put(Types.TINYINT, Byte.class);
    testData.put(Types.SMALLINT, Short.class);
    testData.put(Types.INTEGER, Integer.class);
    testData.put(Types.BIGINT, Long.class);
    testData.put(Types.REAL, Float.class);
    testData.put(Types.FLOAT, Double.class);
    testData.put(Types.DOUBLE, Double.class);
    testData.put(Types.BINARY, byte[].class);
    testData.put(Types.VARBINARY, byte[].class);
    testData.put(Types.LONGVARBINARY, byte[].class);
    testData.put(Types.DATE, java.sql.Date.class);
    testData.put(Types.TIMESTAMP, java.sql.Timestamp.class);
    testData.put(Types.TIME, java.sql.Time.class);
    testData.put(Types.CLOB, java.sql.Clob.class);
    testData.put(Types.BLOB, java.sql.Blob.class);
    testData.put(Types.ARRAY, java.sql.Array.class);
    testData.put(Types.STRUCT, java.sql.Struct.class);
    testData.put(Types.REF, java.sql.Ref.class);
    testData.put(Types.DATALINK, java.net.URL.class);

    for (int type : testData.keySet()) {
        Class result = SQLTypeMapUtil.sqlTypeToClass(type, null);
        log.debug(".testMapping Mapping " + type + " to " + result.getSimpleName());
        assertEquals(testData.get(type), result);
    }/*from w w w  .  j a  va2s.c o m*/

    assertEquals(String.class, SQLTypeMapUtil.sqlTypeToClass(Types.JAVA_OBJECT, "java.lang.String"));
    assertEquals(String.class, SQLTypeMapUtil.sqlTypeToClass(Types.DISTINCT, "java.lang.String"));
}

From source file:org.pentaho.reporting.engine.classic.core.modules.misc.tablemodel.TypeMapper.java

private static Class mapSQLType(final int t) {
    switch (t) {//w  w  w. j  a v  a 2  s  .  com
    case Types.ARRAY:
        return Object[].class;
    case Types.BIGINT:
        return Long.class;
    case Types.BINARY:
        return byteArrayClass;
    case Types.BIT:
        return Boolean.class;
    case Types.BLOB:
        return Blob.class;
    case Types.BOOLEAN: // Types.BOOLEAN was not part of JDK1.2.2
        return Boolean.class;
    case Types.CHAR:
        return String.class;
    case Types.CLOB:
        return Clob.class;
    case Types.DATALINK: // Types.DATALINK was not part of JDK 1.2.2
        return URL.class;
    case Types.DATE:
        return java.sql.Date.class;
    case Types.DECIMAL:
        return java.math.BigDecimal.class;
    case Types.DISTINCT:
        return Object.class;
    case Types.DOUBLE:
        return Double.class;
    case Types.FLOAT:
        return Double.class;
    case Types.INTEGER:
        return Integer.class;
    case Types.JAVA_OBJECT:
        return Object.class;
    case Types.LONGVARBINARY:
        return byteArrayClass;
    case Types.LONGVARCHAR:
        return String.class;
    case Types.NCLOB:
        return NClob.class;
    case Types.NULL:
        return Object.class;
    case Types.NUMERIC:
        return java.math.BigDecimal.class;
    case Types.NCHAR:
    case Types.NVARCHAR:
    case Types.LONGNVARCHAR:
        return String.class;
    case Types.OTHER:
        return Object.class;
    case Types.REAL:
        return Float.class;
    case Types.REF:
        return Ref.class;
    case Types.ROWID:
        return RowId.class;
    case Types.SMALLINT:
        return Short.class;
    case Types.STRUCT:
        return Struct.class;
    case Types.SQLXML:
        return SQLXML.class;
    case Types.TIME:
        return Time.class;
    case Types.TIMESTAMP:
        return Timestamp.class;
    case Types.TINYINT:
        return Byte.class;
    case Types.VARBINARY:
        return byteArrayClass;
    case Types.VARCHAR:
        return String.class;
    default:
        return Object.class;
    }
}

From source file:Spring.Repaso01.ClienteDAO.java

@Override
public void modificacion(Cliente c) {
    String modQuery = "update Cliente set Nombre = ?, Ape1 = ?, Ape2 = ?, Saldo = ? where idCliente = ?";
    Object[] params = new Object[] { c.getNombre(), c.getApe1(), c.getApe2(), c.getSaldo(), c.getIdCliente() };
    int[] types = new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.DECIMAL, Types.INTEGER };
    jdbcTemplate.update(modQuery, params, types);
}

From source file:org.apache.ddlutils.io.converters.NumberConverter.java

/**
 * {@inheritDoc}/*w  w w  .  j  a v a 2  s .  c o  m*/
 */
public Object convertFromString(String textRep, int sqlTypeCode) throws ConversionException {
    if (textRep == null) {
        return null;
    } else {
        Class targetClass = null;

        switch (sqlTypeCode) {
        case Types.BIGINT:
            targetClass = Long.class;
            break;
        case Types.BIT:
        case Types.BOOLEAN:
            targetClass = Boolean.class;
            break;
        case Types.DECIMAL:
        case Types.NUMERIC:
            targetClass = BigDecimal.class;
            break;
        case Types.DOUBLE:
        case Types.FLOAT:
            targetClass = Double.class;
            break;
        case Types.INTEGER:
            targetClass = Integer.class;
            break;
        case Types.REAL:
            targetClass = Float.class;
            break;
        case Types.SMALLINT:
        case Types.TINYINT:
            targetClass = Short.class;
            break;
        }
        return targetClass == null ? textRep : ConvertUtils.convert(textRep, targetClass);
    }
}

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.
 *//*from w  w w  . j  av  a2 s  .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:org.talend.dataquality.record.linkage.ui.composite.table.SortComparator.java

public static ISortComparator getSortComparator(int javaDataType) throws ParseException {
    switch (javaDataType) {
    case Types.DATE:
    case Types.TIME:
        return new SortComparator() {

            @Override/*from www .ja  v a  2 s .c o m*/
            public int compareNotNull(Object value1, Object value2) throws ParseException {
                return java.sql.Date.valueOf(value1.toString())
                        .compareTo(java.sql.Date.valueOf(value2.toString()));
            }

        };
    case Types.TIMESTAMP:
        return new SortComparator() {

            @Override
            public int compareNotNull(Object value1, Object value2) throws ParseException {
                return Timestamp.valueOf(value1.toString()).compareTo(Timestamp.valueOf(value2.toString()));
            }

        };
    case Types.DOUBLE:
    case Types.REAL:
    case Types.FLOAT:
        return new SortComparator() {

            @Override
            public int compareNotNull(Object value1, Object value2) throws ParseException {
                return Double.valueOf(value1.toString()).compareTo(Double.valueOf(value2.toString()));
            }

        };

    case Types.INTEGER:
    case Types.TINYINT:
    case Types.SMALLINT:
    case Types.NUMERIC:

        return new SortComparator() {

            @Override
            public int compareNotNull(Object value1, Object value2) throws ParseException {
                return Integer.valueOf(value1.toString()).compareTo(Integer.valueOf(value2.toString()));
            }

        };
    case Types.BIGINT:
        return new SortComparator() {

            @Override
            public int compareNotNull(Object value1, Object value2) throws ParseException {
                return Long.valueOf(value1.toString()).compareTo(Long.valueOf(value2.toString()));
            }

        };
    case Types.DECIMAL:
        return new SortComparator() {

            @Override
            public int compareNotNull(Object value1, Object value2) throws ParseException {
                if (value1 instanceof BigDecimal) {
                    return ((BigDecimal) value1).compareTo((BigDecimal) value2);
                }
                BigDecimal b1 = new BigDecimal(value1.toString());
                BigDecimal b2 = new BigDecimal(value2.toString());
                return b1.compareTo(b2);
            }

        };
    case Types.BOOLEAN:
    case Types.BIT:
        return new SortComparator() {

            @Override
            public int compareNotNull(Object value1, Object value2) throws ParseException {
                return Boolean.valueOf(value1.toString()).compareTo(Boolean.valueOf(value2.toString()));
            }

        };
    default:// String
        return new SortComparator() {

            @Override
            public int compareNotNull(Object value1, Object value2) throws ParseException {
                return value1.toString().compareTo(value2.toString());
            }

        };

    }

}

From source file:org.apache.openjpa.jdbc.schema.Schemas.java

/**
 * Return the SQL type name for the given {@link Types} constant.
 *///from   w w w  .  j a va  2 s. c o m
public static String getJDBCName(int type) {
    switch (type) {
    case Types.ARRAY:
        return "array";
    case Types.BIGINT:
        return "bigint";
    case Types.BINARY:
        return "binary";
    case Types.BIT:
        return "bit";
    case Types.BLOB:
        return "blob";
    case Types.CHAR:
        return "char";
    case Types.CLOB:
        return "clob";
    case Types.DATE:
        return "date";
    case Types.DECIMAL:
        return "decimal";
    case Types.DISTINCT:
        return "distinct";
    case Types.DOUBLE:
        return "double";
    case Types.FLOAT:
        return "float";
    case Types.INTEGER:
        return "integer";
    case Types.JAVA_OBJECT:
        return "java_object";
    case Types.LONGVARBINARY:
        return "longvarbinary";
    case Types.LONGVARCHAR:
        return "longvarchar";
    case Types.NULL:
        return "null";
    case Types.NUMERIC:
        return "numeric";
    case Types.OTHER:
        return "other";
    case Types.REAL:
        return "real";
    case Types.REF:
        return "ref";
    case Types.SMALLINT:
        return "smallint";
    case Types.STRUCT:
        return "struct";
    case Types.TIME:
        return "time";
    case Types.TIMESTAMP:
        return "timestamp";
    case Types.TINYINT:
        return "tinyint";
    case Types.VARBINARY:
        return "varbinary";
    case Types.VARCHAR:
        return "varchar";
    default:
        return "unknown(" + type + ")";
    }
}

From source file:com.trackplus.ddl.GenericStringValueConverter.java

protected String extractColumnValue(ResultSet resultSet, int columnIdx, int jdbcType)
        throws SQLException, DDLException {
    String value = resultSet.getString(columnIdx);
    if (value != null) {
        switch (jdbcType) {
        case Types.NUMERIC:
        case Types.DECIMAL:
            break;
        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: {
            break;
        }/*from   w ww.j  a  v  a 2  s.c om*/

        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.TIME:
        case Types.CLOB:
        case Types.ARRAY:
        case Types.REF: {
            value = "'" + value.replaceAll("'", "''") + "'";
            break;
        }
        case Types.DATE:
        case Types.TIMESTAMP: {
            Date d = resultSet.getDate(columnIdx);
            Calendar cal = Calendar.getInstance();
            cal.setTime(d);
            int year = cal.get(Calendar.YEAR);
            if (year < 1900) {
                throw new DDLException("Invalid date:" + d);
            } else {
                value = "'" + value + "'";
            }
            break;
        }
        case Types.BLOB:
        case Types.LONGVARBINARY: {
            Blob blobValue = resultSet.getBlob(columnIdx);
            String str = new String(Base64.encodeBase64(blobValue.getBytes(1l, (int) blobValue.length())));
            value = "'" + str + "'";
            break;
        }
        default:
            break;
        }
    }
    return value;
}

From source file:com.streamsets.pipeline.stage.it.AllNullTypesIT.java

@Parameterized.Parameters(name = "type({0})")
public static Collection<Object[]> data() throws Exception {
    return Arrays.asList(new Object[][] { { Field.create(Field.Type.BOOLEAN, null), true, Types.BOOLEAN },
            { Field.create(Field.Type.CHAR, null), true, Types.VARCHAR },
            { Field.create(Field.Type.BYTE, null), false, 0 },
            { Field.create(Field.Type.SHORT, null), true, Types.INTEGER },
            { Field.create(Field.Type.INTEGER, null), true, Types.INTEGER },
            { Field.create(Field.Type.LONG, null), true, Types.BIGINT },
            { Field.create(Field.Type.FLOAT, null), true, Types.FLOAT },
            { Field.create(Field.Type.DOUBLE, null), true, Types.DOUBLE },
            { Field.create(Field.Type.DATE, null), true, Types.DATE },
            { Field.create(Field.Type.DATETIME, null), true, Types.VARCHAR },
            { Field.create(Field.Type.TIME, null), true, Types.VARCHAR },
            { Field.create(Field.Type.DECIMAL, null), true, Types.DECIMAL },
            { Field.create(Field.Type.STRING, null), true, Types.VARCHAR },
            { Field.create(Field.Type.BYTE_ARRAY, null), true, Types.BINARY },
            { Field.create(Field.Type.MAP, null), false, 0 }, { Field.create(Field.Type.LIST, null), false, 0 },
            { Field.create(Field.Type.LIST_MAP, null), false, 0 }, });
}