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.acmsl.queryj.metadata.engines.JdbcTypeManager.java

/**
 * {@inheritDoc}/*from  w  w w  .  j  a v  a2s  .c o  m*/
 */
@NotNull
@Override
public List<Integer> getCompatibleTypesFor(final int type) {
    @NotNull
    final List<Integer> result = new ArrayList<>();

    switch (type) {
    case Types.CHAR:
    case Types.LONGNVARCHAR:
    case Types.LONGVARCHAR:
    case Types.NCHAR:
    case Types.NVARCHAR:
    case Types.VARCHAR:
        result.add(Types.CHAR);
        result.add(Types.LONGNVARCHAR);
        result.add(Types.LONGVARCHAR);
        result.add(Types.NCHAR);
        result.add(Types.NVARCHAR);
        result.add(Types.VARCHAR);
        break;
    case Types.NUMERIC:
    case Types.BIGINT:
    case Types.BIT:
    case Types.BOOLEAN:
    case Types.DECIMAL:
    case Types.DOUBLE:
    case Types.FLOAT:
    case Types.INTEGER:
    case Types.REAL:
    case Types.SMALLINT:
    case Types.TINYINT:
        result.add(Types.NUMERIC);
        result.add(Types.BIGINT);
        result.add(Types.BIT);
        result.add(Types.BOOLEAN);
        result.add(Types.DECIMAL);
        result.add(Types.DOUBLE);
        result.add(Types.FLOAT);
        result.add(Types.INTEGER);
        result.add(Types.REAL);
        result.add(Types.SMALLINT);
        result.add(Types.TINYINT);
        break;
    default:
        break;
    }

    return result;
}

From source file:org.jumpmind.symmetric.service.impl.TriggerRouterService.java

public void saveTriggerRouter(TriggerRouter triggerRouter, boolean updateTriggerRouterTableOnly) {
    if (!updateTriggerRouterTableOnly) {
        saveTrigger(triggerRouter.getTrigger());
        saveRouter(triggerRouter.getRouter());
    }//from  w w w .  j  av  a  2  s  .  co  m
    triggerRouter.setLastUpdateTime(new Date());
    if (0 == sqlTemplate.update(getSql("updateTriggerRouterSql"),
            new Object[] { triggerRouter.getInitialLoadOrder(), triggerRouter.getInitialLoadSelect(),
                    triggerRouter.getInitialLoadDeleteStmt(), triggerRouter.getInitialLoadBatchCount(),
                    triggerRouter.isPingBackEnabled() ? 1 : 0, triggerRouter.getLastUpdateBy(),
                    triggerRouter.getLastUpdateTime(), triggerRouter.isEnabled() ? 1 : 0,
                    triggerRouter.getTrigger().getTriggerId(), triggerRouter.getRouter().getRouterId() },
            new int[] { Types.NUMERIC, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.SMALLINT,
                    Types.VARCHAR, Types.TIMESTAMP, Types.SMALLINT, Types.VARCHAR, Types.VARCHAR })) {
        triggerRouter.setCreateTime(triggerRouter.getLastUpdateTime());
        sqlTemplate.update(getSql("insertTriggerRouterSql"),
                new Object[] { triggerRouter.getInitialLoadOrder(), triggerRouter.getInitialLoadSelect(),
                        triggerRouter.getInitialLoadDeleteStmt(), triggerRouter.getInitialLoadBatchCount(),
                        triggerRouter.isPingBackEnabled() ? 1 : 0, triggerRouter.getCreateTime(),
                        triggerRouter.getLastUpdateBy(), triggerRouter.getLastUpdateTime(),
                        triggerRouter.isEnabled() ? 1 : 0, triggerRouter.getTrigger().getTriggerId(),
                        triggerRouter.getRouter().getRouterId() },
                new int[] { Types.NUMERIC, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.SMALLINT,
                        Types.TIMESTAMP, Types.VARCHAR, Types.TIMESTAMP, Types.SMALLINT, Types.VARCHAR,
                        Types.VARCHAR });
    }

    clearCache();
}

From source file:org.jumpmind.symmetric.service.impl.DataService.java

protected long insertData(ISqlTransaction transaction, final Data data) {
    long id = transaction
            .insertWithGeneratedKey(getSql("insertIntoDataSql"),
                    symmetricDialect.getSequenceKeyName(SequenceIdentifier.DATA),
                    symmetricDialect.getSequenceName(SequenceIdentifier.DATA),
                    new Object[] { data.getTableName(), data.getDataEventType().getCode(), data.getRowData(),
                            data.getPkData(), data.getOldData(),
                            data.getTriggerHistory() != null ? data.getTriggerHistory().getTriggerHistoryId()
                                    : -1,
                            data.getChannelId(), data.getExternalData(), data.getNodeList() },
                    new int[] { Types.VARCHAR, Types.CHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
                            Types.NUMERIC, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR });
    data.setDataId(id);/*from w w w . ja  v  a2 s  . c  o m*/
    return id;
}

From source file:org.jumpmind.symmetric.service.impl.DataService.java

protected void insertDataEvent(ISqlTransaction transaction, long dataId, long batchId, String routerId) {
    try {/*from   w  ww  .j  a  v  a 2 s .com*/
        transaction.prepareAndExecute(getSql("insertIntoDataEventSql"),
                new Object[] { dataId, batchId,
                        StringUtils.isBlank(routerId) ? Constants.UNKNOWN_ROUTER_ID : routerId },
                new int[] { Types.NUMERIC, Types.NUMERIC, Types.VARCHAR });
    } catch (RuntimeException ex) {
        log.error("Could not insert a data event: data_id={} batch_id={} router_id={}",
                new Object[] { dataId, batchId, routerId });
        log.error("", ex);
        throw ex;
    }
}

From source file:org.dspace.storage.rdbms.DatabaseManager.java

private static void loadParameters(PreparedStatement statement, Collection<ColumnInfo> columns, TableRow row)
        throws SQLException {
    int count = 0;
    for (ColumnInfo info : columns) {
        count++;/*  w  w  w.  j  av a2s .co m*/
        String column = info.getCanonicalizedName();
        int jdbctype = info.getType();

        if (row.isColumnNull(column)) {
            statement.setNull(count, jdbctype);
        } else {
            switch (jdbctype) {
            case Types.BIT:
                statement.setBoolean(count, row.getBooleanColumn(column));
                break;

            case Types.INTEGER:
                if (isOracle) {
                    statement.setLong(count, row.getLongColumn(column));
                } else {
                    statement.setInt(count, row.getIntColumn(column));
                }
                break;

            case Types.NUMERIC:
            case Types.DECIMAL:
                statement.setLong(count, row.getLongColumn(column));
                // FIXME should be BigDecimal if TableRow supported that
                break;

            case Types.BIGINT:
                statement.setLong(count, row.getLongColumn(column));
                break;

            case Types.CLOB:
                if (isOracle) {
                    // Support CLOBs in place of TEXT columns in Oracle
                    statement.setString(count, row.getStringColumn(column));
                } else {
                    throw new IllegalArgumentException("Unsupported JDBC type: " + jdbctype);
                }
                break;

            case Types.VARCHAR:
                statement.setString(count, row.getStringColumn(column));
                break;

            case Types.DATE:
                statement.setDate(count, new java.sql.Date(row.getDateColumn(column).getTime()));
                break;

            case Types.TIME:
                statement.setTime(count, new Time(row.getDateColumn(column).getTime()));
                break;

            case Types.TIMESTAMP:
                statement.setTimestamp(count, new Timestamp(row.getDateColumn(column).getTime()));
                break;

            default:
                throw new IllegalArgumentException("Unsupported JDBC type: " + jdbctype);
            }
        }
    }
}

From source file:com.flexive.ejb.beans.PhraseEngineBean.java

/**
 * {@inheritDoc}/*from ww  w  . j  a v a 2s . c  o m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public FxPhraseTreeNode saveTreeNode(FxPhraseTreeNode node) throws FxNoAccessException, FxNotFoundException {
    Connection con = null;
    PreparedStatement ps = null;

    checkMandatorAccess(node.getMandatorId(), FxContext.getUserTicket());
    //load the node's phrase to check if it exists
    FxPhrase checkPhrase = loadPhrase(node.getPhrase().getCategory(), node.getPhrase().getKey(),
            node.getPhrase().getMandator());
    if (!checkPhrase.hasId())
        throw new FxNotFoundException("ex.phrases.noId");
    try {
        // Obtain a database connection
        con = Database.getDbConnection();
        ps = con.prepareStatement(
                "SELECT ID, MANDATOR FROM " + TBL_PHRASE_TREE + " WHERE ID=? AND MANDATOR=? AND CAT=?");
        ps.setInt(3, node.getCategory());
        boolean newNode = node.isNew();
        if (!node.isNew()) {
            //check if the node has an id set but does not exist yet
            ps.setLong(1, node.getId());
            ps.setLong(2, node.getMandatorId());
            ResultSet rs = ps.executeQuery();
            newNode = !(rs != null && rs.next());
        }
        if (node.hasParent()) {
            //check if the parent node exists
            ps.setLong(1, node.getParentNodeId());
            ps.setLong(2, node.getParentNodeMandatorId());
            ResultSet rs = ps.executeQuery();
            if (!(rs != null && rs.next()))
                throw new FxNotFoundException("ex.phrase.tree.parent.notFound", node.getParentNodeId(),
                        node.getParentNodeMandatorId());

        }
        ps.close();
        if (!newNode) {
            ps = con.prepareStatement("UPDATE " + TBL_PHRASE_TREE
                    + " SET PARENTID=?,PARENTMANDATOR=?,PHRASEID=?,PMANDATOR=?,POS=? WHERE ID=? AND MANDATOR=? AND CAT=?");
            if (node.hasParent()) {
                ps.setLong(1, node.getParentNodeId());
                ps.setLong(2, node.getParentNodeMandatorId());
            } else {
                ps.setNull(1, Types.NUMERIC);
                ps.setNull(2, Types.NUMERIC);
            }
            ps.setLong(3, checkPhrase.getId());
            ps.setLong(4, checkPhrase.getMandator());
            if (!node.hasPos())
                node.setPos(getNextNodePos(con, node.getCategory(), node.getParentNodeId(),
                        node.getParentNodeMandatorId(), node.getMandatorId()));
            ps.setLong(5, node.getPos());
            ps.setLong(6, node.getId());
            ps.setLong(7, node.getMandatorId());
            ps.setInt(8, node.getCategory());
            ps.executeUpdate();
            node.getPhrase().setId(checkPhrase.getId());
            return node;
        } else {
            ps = con.prepareStatement("INSERT INTO " + TBL_PHRASE_TREE
                    + " (ID,MANDATOR,PARENTID,PARENTMANDATOR,PHRASEID,PMANDATOR,POS,CAT)VALUES(?,?,?,?,?,?,?,?)");
            final long nodeId = node.isNew() ? fetchNextNodeId(node.getMandatorId(), node.getCategory())
                    : node.getId();
            ps.setLong(1, nodeId);
            ps.setLong(2, node.getMandatorId());
            if (node.hasParent()) {
                ps.setLong(3, node.getParentNodeId());
                ps.setLong(4, node.getParentNodeMandatorId());
            } else {
                ps.setNull(3, Types.NUMERIC);
                ps.setNull(4, Types.NUMERIC);
            }
            ps.setLong(5, checkPhrase.getId());
            ps.setLong(6, checkPhrase.getMandator());
            if (!node.hasPos())
                node.setPos(getNextNodePos(con, node.getCategory(), node.getParentNodeId(),
                        node.getParentNodeMandatorId(), node.getMandatorId()));
            ps.setLong(7, node.getPos());
            ps.setInt(8, node.getCategory());
            ps.executeUpdate();
            node.setId(nodeId);
            node.getPhrase().setId(checkPhrase.getId());
            return node;
        }
    } catch (SQLException exc) {
        EJBUtils.rollback(ctx);
        throw new FxDbException(LOG, exc, "ex.db.sqlError", exc.getMessage()).asRuntimeException();
    } finally {
        Database.closeObjects(PhraseEngineBean.class, con, ps);
    }
}

From source file:org.jumpmind.symmetric.service.impl.DataService.java

public void insertDataEvents(ISqlTransaction transaction, final List<DataEvent> events) {
    if (events.size() > 0) {
        transaction.prepare(getSql("insertIntoDataEventSql"));
        for (DataEvent dataEvent : events) {
            String routerId = dataEvent.getRouterId();
            transaction.addRow(dataEvent,
                    new Object[] { dataEvent.getDataId(), dataEvent.getBatchId(),
                            StringUtils.isBlank(routerId) ? Constants.UNKNOWN_ROUTER_ID : routerId },
                    new int[] { Types.NUMERIC, Types.NUMERIC, Types.VARCHAR });
        }//from ww  w.j a  v a  2 s  .com
        transaction.flush();
    }
}

From source file:org.wso2.carbon.dataservices.core.description.query.SQLQuery.java

private DataEntry getDataEntryFromRS(ResultSet rs) throws SQLException {
    DataEntry dataEntry = new DataEntry();
    ResultSetMetaData metaData = rs.getMetaData();
    int columnCount = metaData.getColumnCount();
    int columnType;
    String value;/*from  w  ww . j av  a  2 s.  c  om*/
    ParamValue paramValue;
    Time sqlTime;
    Date sqlDate;
    Timestamp sqlTimestamp;
    Blob sqlBlob;
    BigDecimal bigDecimal;
    InputStream binInStream;
    boolean useColumnNumbers = this.isUsingColumnNumbers();
    for (int i = 1; i <= columnCount; i++) {
        /* retrieve values according to the column type */
        columnType = metaData.getColumnType(i);
        switch (columnType) {
        /* handle string types */
        case Types.VARCHAR:
            /* fall through */
        case Types.LONGVARCHAR:
            /* fall through */
        case Types.CHAR:
            /* fall through */
        case Types.CLOB:
            /* fall through */
        case Types.NCHAR:
            /* fall through */
        case Types.NCLOB:
            /* fall through */
        case Types.NVARCHAR:
            /* fall through */
        case Types.LONGNVARCHAR:
            value = rs.getString(i);
            paramValue = new ParamValue(value);
            break;
        /* handle numbers */
        case Types.INTEGER:
            /* fall through */
        case Types.TINYINT:
            /* fall through */
        case Types.SMALLINT:
            value = ConverterUtil.convertToString(rs.getInt(i));
            paramValue = new ParamValue(rs.wasNull() ? null : value);
            break;
        case Types.DOUBLE:
            value = ConverterUtil.convertToString(rs.getDouble(i));
            paramValue = new ParamValue(rs.wasNull() ? null : value);
            break;
        case Types.FLOAT:
            value = ConverterUtil.convertToString(rs.getFloat(i));
            paramValue = new ParamValue(rs.wasNull() ? null : value);
            break;
        case Types.BOOLEAN:
            /* fall through */
        case Types.BIT:
            value = ConverterUtil.convertToString(rs.getBoolean(i));
            paramValue = new ParamValue(rs.wasNull() ? null : value);
            break;
        case Types.DECIMAL:
            bigDecimal = rs.getBigDecimal(i);
            if (bigDecimal != null) {
                value = ConverterUtil.convertToString(bigDecimal);
            } else {
                value = null;
            }
            paramValue = new ParamValue(value);
            break;
        /* handle data/time values */
        case Types.TIME:
            /* handle time data type */
            sqlTime = rs.getTime(i);
            if (sqlTime != null) {
                value = this.convertToTimeString(sqlTime);
            } else {
                value = null;
            }
            paramValue = new ParamValue(value);
            break;
        case Types.DATE:
            /* handle date data type */
            sqlDate = rs.getDate(i);
            if (sqlDate != null) {
                value = ConverterUtil.convertToString(sqlDate);
            } else {
                value = null;
            }
            paramValue = new ParamValue(value);
            break;
        case Types.TIMESTAMP:
            sqlTimestamp = rs.getTimestamp(i, calendar);
            if (sqlTimestamp != null) {
                value = this.convertToTimestampString(sqlTimestamp);
            } else {
                value = null;
            }
            paramValue = new ParamValue(value);
            break;
        /* handle binary types */
        case Types.BLOB:
            sqlBlob = rs.getBlob(i);
            if (sqlBlob != null) {
                value = this.getBase64StringFromInputStream(sqlBlob.getBinaryStream());
            } else {
                value = null;
            }
            paramValue = new ParamValue(value);
            break;
        case Types.BINARY:
            /* fall through */
        case Types.LONGVARBINARY:
            /* fall through */
        case Types.VARBINARY:
            binInStream = rs.getBinaryStream(i);
            if (binInStream != null) {
                value = this.getBase64StringFromInputStream(binInStream);
            } else {
                value = null;
            }
            paramValue = new ParamValue(value);
            break;
        /* handling User Defined Types */
        case Types.STRUCT:
            Struct udt = (Struct) rs.getObject(i);
            paramValue = new ParamValue(udt);
            break;
        case Types.ARRAY:
            paramValue = new ParamValue(ParamValue.PARAM_VALUE_ARRAY);
            Array dataArray = (Array) rs.getObject(i);
            if (dataArray == null) {
                break;
            }
            paramValue = this.processSQLArray(dataArray, paramValue);
            break;
        case Types.NUMERIC:
            bigDecimal = rs.getBigDecimal(i);
            if (bigDecimal != null) {
                value = ConverterUtil.convertToString(bigDecimal);
            } else {
                value = null;
            }
            paramValue = new ParamValue(value);
            break;
        case Types.BIGINT:
            value = ConverterUtil.convertToString(rs.getLong(i));
            paramValue = new ParamValue(rs.wasNull() ? null : value);
            break;

        /* handle all other types as strings */
        default:
            value = rs.getString(i);
            paramValue = new ParamValue(value);
            break;
        }
        dataEntry.addValue(useColumnNumbers ? Integer.toString(i) : metaData.getColumnLabel(i), paramValue);
    }
    return dataEntry;
}

From source file:org.springframework.jdbc.core.JdbcTemplateTests.java

public void testBatchUpdateWithListOfObjectArraysPlusTypeInfo() throws Exception {

    final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?";
    final List<Object[]> ids = new ArrayList<Object[]>();
    ids.add(new Object[] { 100 });
    ids.add(new Object[] { 200 });
    final int[] sqlTypes = new int[] { Types.NUMERIC };
    final int[] rowsAffected = new int[] { 1, 2 };

    MockControl ctrlDataSource = MockControl.createControl(DataSource.class);
    DataSource mockDataSource = (DataSource) ctrlDataSource.getMock();
    MockControl ctrlConnection = MockControl.createControl(Connection.class);
    Connection mockConnection = (Connection) ctrlConnection.getMock();
    MockControl ctrlPreparedStatement = MockControl.createControl(PreparedStatement.class);
    PreparedStatement mockPreparedStatement = (PreparedStatement) ctrlPreparedStatement.getMock();
    MockControl ctrlDatabaseMetaData = MockControl.createControl(DatabaseMetaData.class);
    DatabaseMetaData mockDatabaseMetaData = (DatabaseMetaData) ctrlDatabaseMetaData.getMock();

    BatchUpdateTestHelper.prepareBatchUpdateMocks(sql, ids, sqlTypes, rowsAffected, ctrlDataSource,
            mockDataSource, ctrlConnection, mockConnection, ctrlPreparedStatement, mockPreparedStatement,
            ctrlDatabaseMetaData, mockDatabaseMetaData);

    BatchUpdateTestHelper.replayBatchUpdateMocks(ctrlDataSource, ctrlConnection, ctrlPreparedStatement,
            ctrlDatabaseMetaData);/*from w  w  w.  ja  v  a2s.  co m*/

    JdbcTemplate template = new JdbcTemplate(mockDataSource, false);

    int[] actualRowsAffected = template.batchUpdate(sql, ids, sqlTypes);

    assertTrue("executed 2 updates", actualRowsAffected.length == 2);
    assertEquals(rowsAffected[0], actualRowsAffected[0]);
    assertEquals(rowsAffected[1], actualRowsAffected[1]);

    BatchUpdateTestHelper.verifyBatchUpdateMocks(ctrlPreparedStatement, ctrlDatabaseMetaData);
}

From source file:org.apache.sqoop.mapreduce.hcat.SqoopHCatUtilities.java

public static String sqlTypeString(int sqlType) {
    switch (sqlType) {
    case Types.BIT:
        return "BIT";
    case Types.TINYINT:
        return "TINYINT";
    case Types.SMALLINT:
        return "SMALLINT";
    case Types.INTEGER:
        return "INTEGER";
    case Types.BIGINT:
        return "BIGINT";
    case Types.FLOAT:
        return "FLOAT";
    case Types.REAL:
        return "REAL";
    case Types.DOUBLE:
        return "DOUBLE";
    case Types.NUMERIC:
        return "NUMERIC";
    case Types.DECIMAL:
        return "DECIMAL";
    case Types.CHAR:
        return "CHAR";
    case Types.VARCHAR:
        return "VARCHAR";
    case Types.LONGVARCHAR:
        return "LONGVARCHAR";
    case Types.DATE:
        return "DATE";
    case Types.TIME:
        return "TIME";
    case Types.TIMESTAMP:
        return "TIMESTAMP";
    case Types.BINARY:
        return "BINARY";
    case Types.VARBINARY:
        return "VARBINARY";
    case Types.LONGVARBINARY:
        return "LONGVARBINARY";
    case Types.NULL:
        return "NULL";
    case Types.OTHER:
        return "OTHER";
    case Types.JAVA_OBJECT:
        return "JAVA_OBJECT";
    case Types.DISTINCT:
        return "DISTINCT";
    case Types.STRUCT:
        return "STRUCT";
    case Types.ARRAY:
        return "ARRAY";
    case Types.BLOB:
        return "BLOB";
    case Types.CLOB:
        return "CLOB";
    case Types.REF:
        return "REF";
    case Types.DATALINK:
        return "DATALINK";
    case Types.BOOLEAN:
        return "BOOLEAN";
    case Types.ROWID:
        return "ROWID";
    case Types.NCHAR:
        return "NCHAR";
    case Types.NVARCHAR:
        return "NVARCHAR";
    case Types.LONGNVARCHAR:
        return "LONGNVARCHAR";
    case Types.NCLOB:
        return "NCLOB";
    case Types.SQLXML:
        return "SQLXML";
    default:/*from  ww  w . j  a va2 s .c om*/
        return "<UNKNOWN>";
    }
}