Example usage for java.sql Types NUMERIC

List of usage examples for java.sql Types NUMERIC

Introduction

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

Prototype

int NUMERIC

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

Click Source Link

Document

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

Usage

From source file:org.castor.cpa.persistence.sql.keygen.TableKeyGenerator.java

private void assertNumericSqlType(final int sqlType) throws MappingException {
    switch (sqlType) {
    case Types.BIGINT:
    case Types.SMALLINT:
    case Types.INTEGER:
    case Types.DECIMAL:
    case Types.NUMERIC:
        break;//from   w w  w  .  j  a v a  2s .c  o m
    default:
        String msg = Messages.format("mapping.keyGenSQLType", getClass().getName(), sqlType);
        throw new MappingException(msg);
    }
}

From source file:org.apache.sqoop.mapreduce.db.DataDrivenDBInputFormat.java

/**
 * @return the DBSplitter implementation to use to divide the table/query
 * into InputSplits.//from   w w  w  .  j  av  a2 s .  co 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:
    case Types.LONGNVARCHAR:
    case Types.NVARCHAR:
    case Types.NCHAR:
        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:wzw.sql.ResultSetConverter.java

/**
 * ?//  w w w. j  a v  a2 s  .c o  m
 * @param rs
 * @param type Listjava.sql.Types 
 * @return
 * @throws SQLException
 */
public static Object toType(ResultSet rs, int type) throws SQLException {

    if (rs.next()) { // run rs.next()
        switch (type) {
        case Types.INTEGER:
            return new Integer(rs.getInt(1));

        case Types.BIGINT:
            return new Long(rs.getLong(1));

        case Types.VARCHAR:
            return rs.getString(1);

        case Types.FLOAT:
            return new Float(rs.getFloat(1));

        case Types.DECIMAL:
        case Types.DOUBLE:
        case Types.NUMERIC:
            return new Double(rs.getDouble(1));

        case Types.TIMESTAMP:
            return rs.getTimestamp(1);

        case Types.DATE:
            return rs.getDate(1);

        case Types.TIME:
            return rs.getTime(1);

        default:
            return null;
        }
    }
    return null;

}

From source file:org.apache.openjpa.jdbc.sql.H2Dictionary.java

@Override
public int getJDBCType(int metaTypeCode, boolean lob) {
    int type = super.getJDBCType(metaTypeCode, lob);
    switch (type) {
    case Types.BIGINT:
        if (metaTypeCode == JavaTypes.BIGINTEGER)
            return Types.NUMERIC;
        break;/*w  w w .  ja va  2s.  c om*/
    }
    return type;
}

From source file:nl.strohalm.cyclos.utils.hibernate.AmountType.java

public void nullSafeSet(final PreparedStatement ps, final Object object, final int index)
        throws HibernateException, SQLException {
    final Amount amount = (Amount) object;
    BigDecimal value = null;//w  ww.j  ava2s . c om
    Amount.Type type = null;
    if (amount != null) {
        value = amount.getValue();
        type = amount.getType();
    }
    if (value == null) {
        ps.setNull(index, Types.NUMERIC);
    } else {
        ps.setBigDecimal(index, value);
    }
    if (type == null) {
        ps.setNull(index + 1, Types.CHAR);
    } else {
        ps.setString(index + 1, type.getValue());
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("Binding " + value + " to parameter: " + (index));
        LOG.debug("Binding " + (type == null ? null : type.getValue()) + " to parameter: " + (index + 1));
    }

}

From source file:org.apache.ddlutils.platform.postgresql.PostgreSqlPlatform.java

/**
 * Creates a new platform instance./*w  w  w.j ava 2s  .  c  o m*/
 */
public PostgreSqlPlatform() {
    PlatformInfo info = getPlatformInfo();

    info.setPrimaryKeyColumnAutomaticallyRequired(true);
    // this is the default length though it might be changed when building PostgreSQL
    // in file src/include/postgres_ext.h
    info.setMaxIdentifierLength(31);

    info.addNativeTypeMapping(Types.ARRAY, "BYTEA", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.BINARY, "BYTEA", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.BIT, "BOOLEAN");
    info.addNativeTypeMapping(Types.BLOB, "BYTEA", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.BOOLEAN, "BOOLEAN", Types.BIT);
    info.addNativeTypeMapping(Types.CLOB, "TEXT", Types.LONGVARCHAR);
    info.addNativeTypeMapping(Types.DATALINK, "BYTEA", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.DECIMAL, "NUMERIC", Types.NUMERIC);
    info.addNativeTypeMapping(Types.DISTINCT, "BYTEA", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.DOUBLE, "DOUBLE PRECISION");
    info.addNativeTypeMapping(Types.FLOAT, "DOUBLE PRECISION", Types.DOUBLE);
    info.addNativeTypeMapping(Types.JAVA_OBJECT, "BYTEA", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.LONGVARBINARY, "BYTEA");
    info.addNativeTypeMapping(Types.LONGVARCHAR, "TEXT", Types.LONGVARCHAR);
    info.addNativeTypeMapping(Types.NULL, "BYTEA", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.OTHER, "BYTEA", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.REF, "BYTEA", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.STRUCT, "BYTEA", Types.LONGVARBINARY);
    info.addNativeTypeMapping(Types.TINYINT, "SMALLINT", Types.SMALLINT);
    info.addNativeTypeMapping(Types.VARBINARY, "BYTEA", Types.LONGVARBINARY);

    info.setDefaultSize(Types.CHAR, 254);
    info.setDefaultSize(Types.VARCHAR, 254);

    // no support for specifying the size for these types (because they are mapped
    // to BYTEA which back-maps to BLOB)
    info.setHasSize(Types.BINARY, false);
    info.setHasSize(Types.VARBINARY, false);

    setSqlBuilder(new PostgreSqlBuilder(this));
    setModelReader(new PostgreSqlModelReader(this));
}

From source file:com.hangum.tadpole.engine.sql.util.RDBTypeToJavaTypeUtils.java

/**
 * ? ?// ww  w .  j  a v  a2 s.c om
 * 
 * @param sqlType
 * @return
 */
public static boolean isNumberType(int sqlType) {
    switch (sqlType) {
    case Types.BIGINT:
    case Types.DECIMAL:
    case Types.DOUBLE:
    case Types.FLOAT:
    case Types.INTEGER:
    case Types.NUMERIC:
    case Types.BIT:
    case Types.SMALLINT:
    case Types.TINYINT:
        return true;
    }

    return false;
}

From source file:architecture.ee.web.logo.dao.jdbc.JdbcLogoImageDao.java

public void addLogoImage(LogoImage logoImage, InputStream is) {
    LogoImage toUse = logoImage;//from w  w w .j  a  va 2 s .c om
    long logoIdToUse = logoImage.getLogoId();
    if (logoIdToUse < 1) {
        logoIdToUse = getNextId(sequencerName);
        logoImage.setLogoId(logoIdToUse);
    }

    getExtendedJdbcTemplate().update(
            getBoundSql("ARCHITECTURE_WEB.RESET_LOGO_IMAGE_BY_OBJECT_TYPE_AND_OBJECT_ID").getSql(),
            new SqlParameterValue(Types.INTEGER, toUse.getObjectType()),
            new SqlParameterValue(Types.NUMERIC, toUse.getObjectId()));

    getExtendedJdbcTemplate().update(getBoundSql("ARCHITECTURE_WEB.CREATE_LOGO_IMAGE").getSql(),
            new SqlParameterValue(Types.NUMERIC, logoImage.getLogoId()),
            new SqlParameterValue(Types.NUMERIC, logoImage.getObjectType()),
            new SqlParameterValue(Types.NUMERIC, logoImage.getObjectId()),
            new SqlParameterValue(Types.NUMERIC, logoImage.isPrimary() ? 1 : 0),
            new SqlParameterValue(Types.VARCHAR, logoImage.getFilename()),
            new SqlParameterValue(Types.NUMERIC, logoImage.getImageSize()),
            new SqlParameterValue(Types.VARCHAR, logoImage.getImageContentType()),
            new SqlParameterValue(Types.DATE, logoImage.getModifiedDate()),
            new SqlParameterValue(Types.DATE, logoImage.getCreationDate()));
    updateImageImputStream(logoImage, is);
}

From source file:au.com.ish.derbydump.derbydump.metadata.Column.java

/**
 * Get a string value for the value in this column in the datarow
 * /* w  w w  .ja  va2  s .c o m*/
 * @param dataRow The row which we are exporting
 * @return an SQL statement compliant string version of the value
 */
public String toString(ResultSet dataRow) throws SQLException {

    switch (getColumnDataType()) {
    case Types.BINARY:
    case Types.VARBINARY:
    case Types.BLOB: {
        Blob obj = dataRow.getBlob(columnName);
        return (obj == null) ? "NULL" : processBinaryData(obj);
    }

    case Types.CLOB: {
        Clob obj = dataRow.getClob(columnName);
        return (obj == null) ? "NULL" : processClobData(obj);
    }

    case Types.CHAR:
    case Types.LONGNVARCHAR:
    case Types.VARCHAR: {
        String obj = dataRow.getString(columnName);
        return (obj == null) ? "NULL" : processStringData(obj);
    }

    case Types.TIME: {
        Time obj = dataRow.getTime(columnName);
        return (obj == null) ? "NULL" : processStringData(obj.toString());
    }

    case Types.DATE: {
        Date obj = dataRow.getDate(columnName);
        return (obj == null) ? "NULL" : processStringData(obj.toString());
    }

    case Types.TIMESTAMP: {
        Timestamp obj = dataRow.getTimestamp(columnName);
        return (obj == null) ? "NULL" : processStringData(obj.toString());
    }

    case Types.SMALLINT: {
        Object obj = dataRow.getObject(columnName);
        return (obj == null) ? "NULL" : obj.toString();
    }

    case Types.BIGINT: {
        Object obj = dataRow.getObject(columnName);
        return (obj == null) ? "NULL" : obj.toString();
    }

    case Types.INTEGER: {
        Object obj = dataRow.getObject(columnName);
        return (obj == null) ? "NULL" : obj.toString();
    }

    case Types.NUMERIC:
    case Types.DECIMAL: {
        BigDecimal obj = dataRow.getBigDecimal(columnName);
        return (obj == null) ? "NULL" : String.valueOf(obj);
    }

    case Types.REAL:
    case Types.FLOAT: {
        Float obj = dataRow.getFloat(columnName);
        // dataRow.getFloat() always returns a value. only way to check the null is wasNull() method
        return (dataRow.wasNull()) ? "NULL" : String.valueOf(obj);
    }

    case Types.DOUBLE: {
        Double obj = dataRow.getDouble(columnName);
        return (dataRow.wasNull()) ? "NULL" : String.valueOf(obj);
    }

    default: {
        Object obj = dataRow.getObject(columnName);
        return (obj == null) ? "NULL" : obj.toString();
    }
    }
}

From source file:architecture.ee.web.community.timeline.dao.jdbc.JdbcTimelineDao.java

public List<Long> getTimelineIds(int objectType, long objectId) {
    return getExtendedJdbcTemplate().query(getBoundSql(
            "ARCHITECTURE_COMMUNITY.SELECT_TIMELINE_IDS_BY_OBJECT_TYPE_AND_OBJECT_ID_WITH_DATE_DESC").getSql(),
            new RowMapper<Long>() {
                public Long mapRow(ResultSet rs, int rowNum) throws SQLException {
                    return rs.getLong(1);
                }/*from  w w  w.j av  a 2 s.c om*/
            }, new SqlParameterValue(Types.NUMERIC, objectType),
            new SqlParameterValue(Types.NUMERIC, objectId));
}