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:com.egeniuss.appmarket.controller.AppManagerController.java

@RequestMapping("/uploadApp.html")
public @ResponseBody Map<String, Object> uploadApp(@RequestParam(required = false) MultipartFile app,
        HttpServletRequest request) {/*from w  w  w .  j  a v a 2s  .  co  m*/
    Date now = new Date();
    long time = now.getTime();
    String appFileName = app.getOriginalFilename();
    String realFileName = time + appFileName.substring(appFileName.lastIndexOf("."));
    Map<String, Object> msg = new HashMap<String, Object>();
    try {
        FileUtils.copyInputStreamToFile(app.getInputStream(), new File(appStore.concat(realFileName)));
    } catch (IOException e) {
        LOGGER.error("?", e);
        msg.put("errcode", -1);
        msg.put("errmsg", "<br/>" + e.getMessage());
        return msg;
    }
    SimpleDateFormat formator = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    StringTokenizer linemsg = new StringTokenizer(request.getParameter("releaseNote"), "\n");
    StringBuilder releaseNoteSb = new StringBuilder();
    while (linemsg.hasMoreElements()) {
        releaseNoteSb.append(linemsg.nextElement()).append("\\n");
    }
    Object[] args = new Object[] { time, request.getParameter("appKey"), request.getParameter("appPlatform"),
            request.getParameter("appEnv"), request.getParameter("versionNum"), app.getSize(),
            releaseNoteSb.toString(), realFileName, formator.format(now) };
    int[] argTypes = new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
            Types.DECIMAL, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR };
    jdbcTemplate.update(
            "insert into APP_MARKET (APP_ID, APP_KEY, APP_PLATFORM, APP_ENV, VERSION_NUM, APP_SIZE, RELEASE_NOTE, FILE_NAME, CREATE_TIME) values (?, ?, ?, ?, ?, ?, ?, ?, ?)",
            args, argTypes);
    msg.put("errcode", 0);
    msg.put("errmsg", "ok");
    return msg;
}

From source file:com.xpfriend.fixture.cast.temp.TypeConverter.java

private static Class<?> getJavaType(int sqltype, int precision, int scale) {
    switch (sqltype) {
    case Types.BIGINT:
        return Long.class;
    case Types.BIT:
        return Boolean.class;
    case Types.BOOLEAN:
        return Boolean.class;
    case Types.CHAR:
        return String.class;
    case Types.DECIMAL:
        return getNumericType(precision, scale);
    case Types.DOUBLE:
        return Double.class;
    case Types.FLOAT:
        return Double.class;
    case Types.INTEGER:
        return Integer.class;
    case Types.LONGVARCHAR:
        return String.class;
    case Types.NUMERIC:
        return getNumericType(precision, scale);
    case Types.REAL:
        return Float.class;
    case Types.SMALLINT:
        return Short.class;
    case Types.DATE:
        return java.sql.Timestamp.class;
    case Types.TIME:
        return java.sql.Time.class;
    case Types.TIMESTAMP:
        return java.sql.Timestamp.class;
    case Types.TINYINT:
        return Byte.class;
    case Types.VARCHAR:
        return String.class;
    case Types.BLOB:
        return byte[].class;
    case Types.LONGVARBINARY:
        return byte[].class;
    case Types.CLOB:
        return String.class;
    case Types.BINARY:
        return byte[].class;
    case Types.VARBINARY:
        return byte[].class;
    case Types.NVARCHAR:
        return String.class;
    case Types.NCHAR:
        return String.class;
    case Types.LONGNVARCHAR:
        return String.class;
    case -155:/*ww w .  ja  va2 s . c o m*/
        return java.sql.Timestamp.class;
    default:
        return Object.class;
    }
}

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

/**
 * Initialize the HIGH-LOW key generator.
 * //from   w w w  .  j av  a  2s.  c om
 * @param factory A PersistenceFactory instance.
 * @param params Database engine specific parameters. 
 * @param sqlType A SQLTypidentifier.
 * @throws MappingException if this key generator is not compatible with the
 *         persistance factory.
 */
public HighLowKeyGenerator(final PersistenceFactory factory, final Properties params, final int sqlType)
        throws MappingException {
    super(factory);
    _factory = factory;
    _sqlType = sqlType;

    if ((sqlType != Types.INTEGER) && (sqlType != Types.BIGINT) && (sqlType != Types.NUMERIC)
            && (sqlType != Types.DECIMAL)) {
        String msg = Messages.format("mapping.keyGenSQLType", getClass().getName(), new Integer(sqlType));
        throw new MappingException(msg);
    }

    initFromParameters(params);
}

From source file:com.btobits.automator.ant.sql.task.SQLCompareTask.java

private void verify() throws Exception {
    final LinkedList<SQLCompareTask.VerifyCell> rows = impl.getVerifySqls();
    for (final SQLCompareTask.VerifyCell sqlRow : rows) {
        sqlRow.validate();//from   w  ww . ja  v a 2s  . co m

        switch (getColumnType(sqlRow)) {
        case Types.DOUBLE: {
            final Double val = (Double) getRowValue(sqlRow);

            if (val == null) {
                errors.add("Error compare row, row not exist [" + sqlRow.toString() + "].");
            }

            final DoubleValidator doubleValidator = new DoubleValidator();
            if (doubleValidator.isValid(sqlRow.getValue())) {
                final Double dbValue = doubleValidator.validate(sqlRow.getValue());
                if (!dbValue.equals(val)) {
                    errors.add("Error compare row [" + sqlRow.getRow() + "], field [" + sqlRow.getField()
                            + "], value [" + sqlRow.getValue() + " != " + val + "]");
                }
            } else {
                errors.add("Error cast field [" + sqlRow.toString() + "] to Double value.");
            }
        }
            break;

        case Types.FLOAT: {
            final Float val = (Float) getRowValue(sqlRow);

            if (val == null) {
                errors.add("Error compare row, row not exist [" + sqlRow.toString() + "].");
            }

            final FloatValidator validator = new FloatValidator();
            if (validator.isValid(sqlRow.getValue())) {
                final Float dbValue = validator.validate(sqlRow.getValue());
                if (!dbValue.equals(val)) {
                    errors.add("Error compare row [" + sqlRow.getRow() + "], field [" + sqlRow.getField()
                            + "], value [" + sqlRow.getValue() + " != " + val + "]");
                }
            } else {
                errors.add("Error cast field [" + sqlRow.toString() + "] to Float value.");
            }
        }
            break;

        case Types.DECIMAL: {
            final BigDecimal val = (BigDecimal) getRowValue(sqlRow);

            if (val == null) {
                errors.add("Error compare row, row not exist [" + sqlRow.toString() + "].");
            }

            final BigDecimalValidator validator = new BigDecimalValidator();
            if (validator.isValid(sqlRow.getValue())) {
                BigDecimal dbValue = validator.validate(sqlRow.getValue());
                dbValue = dbValue.setScale(val.scale());
                if (!dbValue.equals(val)) {
                    errors.add("Error compare row [" + sqlRow.getRow() + "], field [" + sqlRow.getField()
                            + "], value [" + sqlRow.getValue() + " != " + val + "]");
                }
            } else {
                errors.add("Error cast field [" + sqlRow.toString() + "] to Decimal value.");
            }
        }
            break;

        case Types.DATE: {
            final Date val = (Date) getDateRowValue(sqlRow);

            if (val == null) {
                errors.add("Error compare row, row not exist [" + sqlRow.toString() + "].");
            }

            final DateValidator validator = DateValidator.getInstance();
            if (validator.isValid(sqlRow.getValue(), "yyyy-MM-dd")) {
                final Date dbValue = validator.validate(sqlRow.getValue(), "yyyy-MM-dd");
                if (!dbValue.equals(val)) {
                    errors.add("Error compare row [" + sqlRow.getRow() + "], field [" + sqlRow.getField()
                            + "], value [" + sqlRow.getValue() + " != " + val + "]");
                }
            } else {
                errors.add("Error cast field [" + sqlRow.toString() + "] to Date value.");
            }
        }
            break;

        case Types.TIME: {
            final Date val = (Date) getTimeRowValue(sqlRow);
            if (val == null) {
                errors.add("Error compare row, row not exist [" + sqlRow.toString() + "].");
            }

            final TimeValidator validator = TimeValidator.getInstance();
            if (validator.isValid(sqlRow.getValue(), "HH:mm:ss")) {
                final Calendar dbValue = validator.validate(sqlRow.getValue(), "HH:mm:ss");
                final Calendar dbVal = Calendar.getInstance();
                dbVal.setTime(val);

                if (validator.compareHours(dbValue, dbVal) != 0 || validator.compareMinutes(dbValue, dbVal) != 0
                        || validator.compareSeconds(dbValue, dbVal) != 0) {
                    errors.add("Error compare row [" + sqlRow.getRow() + "], field [" + sqlRow.getField()
                            + "], value [" + sqlRow.getValue() + " != " + val + "]");
                }
            } else {
                errors.add("Error cast field [" + sqlRow.toString() + "] to Time value.");
            }
        }
            break;

        case Types.TIMESTAMP: {
            final Date val = getDateTimeRowValue(sqlRow);
            if (val == null) {
                errors.add("Error compare row, row not exist [" + sqlRow.toString() + "].");
            }

            final CalendarValidator validatorDate = CalendarValidator.getInstance();
            final TimeValidator validatorTime = TimeValidator.getInstance();
            if (validatorDate.isValid(sqlRow.getValue(), "yyyy-MM-dd HH:mm:ss")) {
                final Calendar dbValue = validatorDate.validate(sqlRow.getValue(), "yyyy-MM-dd HH:mm:ss");
                final Calendar dbVal = Calendar.getInstance();
                dbVal.setTimeInMillis(val.getTime());
                if (validatorDate.compareDates(dbVal, dbValue) != 0
                        || validatorTime.compareHours(dbValue, dbVal) != 0
                        || validatorTime.compareMinutes(dbValue, dbVal) != 0
                        || validatorTime.compareSeconds(dbValue, dbVal) != 0) {
                    errors.add("Error compare row [" + sqlRow.getRow() + "], field [" + sqlRow.getField()
                            + "], value [" + sqlRow.getValue() + " != " + val + "]");
                }
            } else {
                errors.add("Error cast field [" + sqlRow.toString() + "] to Timestamp value.");
            }
        }
            break;

        default: {
            final String dbValue = getStringRowValue(sqlRow);
            if (dbValue == null) {
                errors.add("Error compare row, row not exist [" + sqlRow.toString() + "].");
            } else if (!StringUtils.equals(sqlRow.getValue(), dbValue)) {
                errors.add("Error compare row [" + sqlRow.getRow() + "], field [" + sqlRow.getField()
                        + "], value [" + sqlRow.getValue() + " != " + dbValue + "]");
            }
        }
        }
    }
}

From source file:org.apache.ddlutils.platform.JdbcModelReader.java

/**
 * Creates a new model reader instance.// www  .ja v  a 2  s  .  c  o  m
 * 
 * @param platform The plaftform this builder belongs to
 */
public JdbcModelReader(Platform platform) {
    _platform = platform;

    _defaultSizes.put(new Integer(Types.CHAR), "254");
    _defaultSizes.put(new Integer(Types.VARCHAR), "254");
    _defaultSizes.put(new Integer(Types.LONGVARCHAR), "254");
    _defaultSizes.put(new Integer(Types.BINARY), "254");
    _defaultSizes.put(new Integer(Types.VARBINARY), "254");
    _defaultSizes.put(new Integer(Types.LONGVARBINARY), "254");
    _defaultSizes.put(new Integer(Types.INTEGER), "32");
    _defaultSizes.put(new Integer(Types.BIGINT), "64");
    _defaultSizes.put(new Integer(Types.REAL), "7,0");
    _defaultSizes.put(new Integer(Types.FLOAT), "15,0");
    _defaultSizes.put(new Integer(Types.DOUBLE), "15,0");
    _defaultSizes.put(new Integer(Types.DECIMAL), "15,15");
    _defaultSizes.put(new Integer(Types.NUMERIC), "15,15");

    _columnsForTable = initColumnsForTable();
    _columnsForColumn = initColumnsForColumn();
    _columnsForPK = initColumnsForPK();
    _columnsForFK = initColumnsForFK();
    _columnsForIndex = initColumnsForIndex();
}

From source file:org.efaps.db.wrapper.AbstractSQLInsertUpdate.java

/**
 * Defines a new column <code>_columnName</code> with {@link Double}
 * <code>_value</code> within this SQL insert / update statement.
 *
 * @param _columnName   name of the column
 * @param _value        value of the column
 * @return this SQL statement//from   ww  w  .  j a  va2s .  c  o m
 */
@SuppressWarnings("unchecked")
public STMT column(final String _columnName, final Double _value) {
    this.columnWithValues.add(new AbstractSQLInsertUpdate.AbstractColumnWithValue<Double>(_columnName, _value) {
        @Override
        public void set(final int _index, final PreparedStatement _stmt) throws SQLException {
            if (getValue() == null) {
                _stmt.setNull(_index, Types.DECIMAL);
            } else {
                _stmt.setDouble(_index, getValue());
            }
        }
    });
    return (STMT) this;
}

From source file:org.eclipse.ecr.core.storage.sql.jdbc.dialect.DialectOracle.java

@Override
public boolean isAllowedConversion(int expected, int actual, String actualName, int actualSize) {
    // Oracle internal conversions
    if (expected == Types.DOUBLE && actual == Types.FLOAT) {
        return true;
    }/*from  w w w.j a va2 s . com*/
    if (expected == Types.VARCHAR && actual == Types.OTHER && actualName.equals("NVARCHAR2")) {
        return true;
    }
    if (expected == Types.CLOB && actual == Types.OTHER && actualName.equals("NCLOB")) {
        return true;
    }
    if (expected == Types.BIT && actual == Types.DECIMAL && actualName.equals("NUMBER") && actualSize == 1) {
        return true;
    }
    if (expected == Types.TINYINT && actual == Types.DECIMAL && actualName.equals("NUMBER")
            && actualSize == 3) {
        return true;
    }
    if (expected == Types.INTEGER && actual == Types.DECIMAL && actualName.equals("NUMBER")
            && actualSize == 10) {
        return true;
    }
    if (expected == Types.BIGINT && actual == Types.DECIMAL && actualName.equals("NUMBER")
            && actualSize == 19) {
        return true;
    }
    // CLOB vs VARCHAR compatibility
    if (expected == Types.VARCHAR && actual == Types.OTHER && actualName.equals("NCLOB")) {
        return true;
    }
    if (expected == Types.CLOB && actual == Types.OTHER && actualName.equals("NVARCHAR2")) {
        return true;
    }
    return false;
}

From source file:ro.nextreports.engine.querybuilder.sql.dialect.AbstractDialect.java

protected void registerDefaultJavaTypes() {
    registerJavaType(Types.BIT, Boolean.class.getName());
    registerJavaType(Types.TINYINT, Byte.class.getName());
    registerJavaType(Types.SMALLINT, Short.class.getName());
    //       registerJavaType(Types.CHAR, Character.class.getName());
    registerJavaType(Types.CHAR, String.class.getName());
    registerJavaType(Types.VARCHAR, String.class.getName());
    registerJavaType(Types.DATE, Date.class.getName());
    registerJavaType(Types.TIME, Time.class.getName());
    registerJavaType(Types.TIMESTAMP, Timestamp.class.getName());
    registerJavaType(Types.DOUBLE, Double.class.getName());
    registerJavaType(Types.FLOAT, Float.class.getName());
    registerJavaType(Types.INTEGER, Integer.class.getName());
    registerJavaType(Types.BIGINT, BigInteger.class.getName());
    //       registerJavaType(Types.BIGINT, Long.class.getName());       
    registerJavaType(Types.NUMERIC, BigDecimal.class.getName());
    registerJavaType(Types.DECIMAL, BigDecimal.class.getName());
    registerJavaType(Types.BINARY, byte[].class.getName());
    registerJavaType(Types.VARBINARY, byte[].class.getName());

    registerJavaType(Types.BLOB, String.class.getName());
    registerJavaType(Types.CLOB, String.class.getName());
    registerJavaType(Types.REAL, String.class.getName());
    registerJavaType(Types.OTHER, Object.class.getName());
}

From source file:org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplateTests.java

public void testExecuteWithTypedParameters() throws SQLException {
    mockPreparedStatement.setObject(1, new Integer(1), Types.DECIMAL);
    ctrlPreparedStatement.setVoidCallable();
    mockPreparedStatement.setObject(2, new Integer(1), Types.INTEGER);
    ctrlPreparedStatement.setVoidCallable();
    mockPreparedStatement.executeUpdate();
    ctrlPreparedStatement.setReturnValue(1);
    if (debugEnabled) {
        mockPreparedStatement.getWarnings();
        ctrlPreparedStatement.setReturnValue(null);
    }//w w  w .j a v a  2  s.c o  m
    mockPreparedStatement.close();
    ctrlPreparedStatement.setVoidCallable();

    mockConnection.prepareStatement(UPDATE_NAMED_PARAMETERS_PARSED);
    ctrlConnection.setReturnValue(mockPreparedStatement);

    replay();

    NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(mockDataSource);
    Map params = new HashMap();
    params.put("perfId", new SqlParameterValue(Types.DECIMAL, new Integer(1)));
    params.put("priceId", new SqlParameterValue(Types.INTEGER, new Integer(1)));
    assertEquals("result", jt.execute(UPDATE_NAMED_PARAMETERS, params, new PreparedStatementCallback() {
        public Object doInPreparedStatement(PreparedStatement ps) throws SQLException {
            assertEquals(mockPreparedStatement, ps);
            ps.executeUpdate();
            return "result";
        }
    }));
}

From source file:org.syncope.core.util.ImportExport.java

private void setParameters(final String tableName, final Attributes atts, final Query query) {

    Map<String, Integer> colTypes = new HashMap<String, Integer>();

    Connection conn = DataSourceUtils.getConnection(dataSource);
    ResultSet rs = null;/*from ww  w  .j  av a  2s  .co m*/
    Statement stmt = null;
    try {
        stmt = conn.createStatement();
        rs = stmt.executeQuery("SELECT * FROM " + tableName);
        for (int i = 0; i < rs.getMetaData().getColumnCount(); i++) {
            colTypes.put(rs.getMetaData().getColumnName(i + 1).toUpperCase(),
                    rs.getMetaData().getColumnType(i + 1));
        }
    } catch (SQLException e) {
        LOG.error("While", e);
    } finally {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException e) {
                LOG.error("While closing statement", e);
            }
        }
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                LOG.error("While closing result set", e);
            }
        }
        DataSourceUtils.releaseConnection(conn, dataSource);
    }

    for (int i = 0; i < atts.getLength(); i++) {
        Integer colType = colTypes.get(atts.getQName(i).toUpperCase());
        if (colType == null) {
            LOG.warn("No column type found for {}", atts.getQName(i).toUpperCase());
            colType = Types.VARCHAR;
        }

        switch (colType) {
        case Types.NUMERIC:
        case Types.REAL:
        case Types.INTEGER:
        case Types.TINYINT:
            try {
                query.setParameter(i + 1, Integer.valueOf(atts.getValue(i)));
            } catch (NumberFormatException e) {
                LOG.error("Unparsable Integer '{}'", atts.getValue(i));
                query.setParameter(i + 1, atts.getValue(i));
            }
            break;

        case Types.DECIMAL:
        case Types.BIGINT:
            try {
                query.setParameter(i + 1, Long.valueOf(atts.getValue(i)));
            } catch (NumberFormatException e) {
                LOG.error("Unparsable Long '{}'", atts.getValue(i));
                query.setParameter(i + 1, atts.getValue(i));
            }
            break;

        case Types.DOUBLE:
            try {
                query.setParameter(i + 1, Double.valueOf(atts.getValue(i)));
            } catch (NumberFormatException e) {
                LOG.error("Unparsable Double '{}'", atts.getValue(i));
                query.setParameter(i + 1, atts.getValue(i));
            }
            break;

        case Types.FLOAT:
            try {
                query.setParameter(i + 1, Float.valueOf(atts.getValue(i)));
            } catch (NumberFormatException e) {
                LOG.error("Unparsable Float '{}'", atts.getValue(i));
                query.setParameter(i + 1, atts.getValue(i));
            }
            break;

        case Types.DATE:
        case Types.TIME:
        case Types.TIMESTAMP:
            try {
                query.setParameter(i + 1, DateUtils.parseDate(atts.getValue(i), SyncopeConstants.DATE_PATTERNS),
                        TemporalType.TIMESTAMP);
            } catch (ParseException e) {
                LOG.error("Unparsable Date '{}'", atts.getValue(i));
                query.setParameter(i + 1, atts.getValue(i));
            }
            break;

        case Types.BIT:
        case Types.BOOLEAN:
            query.setParameter(i + 1, "1".equals(atts.getValue(i)) ? Boolean.TRUE : Boolean.FALSE);
            break;

        default:
            query.setParameter(i + 1, atts.getValue(i));
        }
    }
}