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.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplateTests.java

public void testBatchUpdateWithSqlParameterSourcePlusTypeInfo() throws Exception {

    final String sqlToUse = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?";
    final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = :id";
    final SqlParameterSource[] ids = new SqlParameterSource[2];
    ids[0] = new MapSqlParameterSource().addValue("id", 100, Types.NUMERIC);
    ids[1] = new MapSqlParameterSource().addValue("id", 200, Types.NUMERIC);
    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(sqlToUse, ids, sqlTypes, rowsAffected, ctrlDataSource,
            mockDataSource, ctrlConnection, mockConnection, ctrlPreparedStatement, mockPreparedStatement,
            ctrlDatabaseMetaData, mockDatabaseMetaData);

    BatchUpdateTestHelper.replayBatchUpdateMocks(ctrlDataSource, ctrlConnection, ctrlPreparedStatement,
            ctrlDatabaseMetaData);/*from ww w.  j  a  v a 2  s.com*/

    JdbcTemplate template = new JdbcTemplate(mockDataSource, false);
    NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(template);

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

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

    BatchUpdateTestHelper.verifyBatchUpdateMocks(ctrlPreparedStatement, ctrlDatabaseMetaData);

}

From source file:ca.sqlpower.architect.ddl.LiquibaseDDLGenerator.java

private boolean isNumericType(GenericTypeDescriptor td) {
    int type = td.getDataType();
    return (type == Types.BIGINT || type == Types.INTEGER || type == Types.DECIMAL || type == Types.DOUBLE
            || type == Types.FLOAT || type == Types.NUMERIC || type == Types.REAL || type == Types.SMALLINT
            || type == Types.TINYINT);
}

From source file:com.redhat.rhn.domain.config.ConfigurationFactory.java

/**
 * Using a stored procedure that looks up the config info and will
 * create one if it does not exist./*from   w  w  w  .j  a  va  2  s.com*/
 * @param user The linux username associated with a file
 * @param group The linux groupname associated with a file
 * @param filemode The three digit file mode (ex: 655)
 * @param selinuxCtx The SELinux context
 * @return The id of the found config info
 */
private static Long lookupConfigInfo(String user, String group, Long filemode, String selinuxCtx,
        String symlinkTargetPath) {
    CallableMode m = ModeFactory.getCallableMode("config_queries", "lookup_config_info");

    Map inParams = new HashMap();
    Map outParams = new HashMap();

    inParams.put("username_in", user);
    inParams.put("groupname_in", group);
    inParams.put("filemode_in", filemode);
    if ((selinuxCtx == null) || (selinuxCtx.isEmpty())) {
        inParams.put("selinuxCtx_in", null);
    } else {
        inParams.put("selinuxCtx_in", selinuxCtx);
    }
    if (!StringUtils.isBlank(symlinkTargetPath)) {
        ConfigFileName fn = lookupOrInsertConfigFileName(symlinkTargetPath);
        inParams.put("symlink_target_file_in", fn.getId());
    } else {
        inParams.put("symlink_target_file_in", null);
    }

    outParams.put("info_id", new Integer(Types.NUMERIC));

    Map out = m.execute(inParams, outParams);

    return (Long) out.get("info_id");
}

From source file:ca.sqlpower.architect.swingui.TestPlayPen.java

/**
 * This tests that copying and pasting a table with source information into
 * the play pen works. This also confirms that the new table copied uses
 * the table reverse engineered from as its source.
 *//*from   www  .ja v a2 s  . co m*/
public void testPasteReverseEngineeredTable() throws Exception {
    SQLDatabase db = new SQLDatabase();
    pp.getSession().getRootObject().addChild(db);
    SQLColumn sourceCol = new SQLColumn();
    SQLTable sourceTable = new SQLTable(db, true);
    sourceTable.addColumn(sourceCol);
    SQLTable table = new SQLTable(db, "NewTable", "Remarks", "TABLE", true);
    final SQLColumn col1 = new SQLColumn(table, "NewCol1", Types.VARCHAR, 50, 0);
    col1.setSourceColumn(sourceCol);
    table.addColumn(col1);
    final SQLColumn col2 = new SQLColumn(table, "NewCol2", Types.NUMERIC, 50, 0);
    col2.setSourceColumn(sourceCol);
    table.addColumn(col2);

    DuplicateProperties duplicateProperties = ASUtils.createDuplicateProperties(pp.getSession(), table);
    pp.importTableCopy(table, new Point(0, 0), duplicateProperties);
    assertEquals(1, pp.getTables().size());
    SQLTable copy = pp.getTables().get(0);
    assertEquals("NewTable", copy.getName());
    assertEquals(2, copy.getColumns().size());
    assertTrue(copy.getColumnByName("NewCol1") != null);
    assertTrue(copy.getColumnByName("NewCol2") != null);
    assertEquals(col1, copy.getColumnByName("NewCol1").getSourceColumn());
    assertEquals(col2, copy.getColumnByName("NewCol2").getSourceColumn());
}

From source file:architecture.ee.web.community.page.dao.jdbc.JdbcPageDao.java

public void delete(Page page) {

    if (page.getVersionId() == -1) {
        List<Long> bodyIds = getExtendedJdbcTemplate().queryForList(
                getBoundSql("ARCHITECTURE_COMMUNITY.SELETE_PAGE_BODY_IDS").getSql(), Long.class,
                new SqlParameterValue(Types.NUMERIC, page.getPageId()));
        getExtendedJdbcTemplate().update(
                getBoundSql("ARCHITECTURE_COMMUNITY.DELETE_PAGE_BODY_VERSIONS").getSql(),
                new SqlParameterValue(Types.NUMERIC, page.getPageId()));
        for (long bodyId : bodyIds) {
            getExtendedJdbcTemplate().update(getBoundSql("ARCHITECTURE_COMMUNITY.DELETE_PAGE_BODY").getSql(),
                    new SqlParameterValue(Types.NUMERIC, bodyId));
        }/*  w w  w  .j a  v a2  s .c  om*/
        getExtendedJdbcTemplate().update(getBoundSql("ARCHITECTURE_COMMUNITY.DELETE_PAGE_VERSIONS").getSql(),
                new SqlParameterValue(Types.NUMERIC, page.getPageId()));
        getExtendedJdbcTemplate().update(getBoundSql("ARCHITECTURE_COMMUNITY.DELETE_PAGE_PROPERTIES").getSql(),
                new SqlParameterValue(Types.NUMERIC, page.getPageId()));
        getExtendedJdbcTemplate().update(getBoundSql("ARCHITECTURE_COMMUNITY.DELETE_PAGE").getSql(),
                new SqlParameterValue(Types.NUMERIC, page.getPageId()));
    }
}

From source file:org.nuxeo.ecm.core.storage.sql.jdbc.dialect.DialectOracle.java

@Override
public Serializable[] getArrayResult(Array array) throws SQLException {
    Serializable[] ids;//w  w w . ja va 2  s  . co  m
    if (array.getBaseType() == Types.NUMERIC) {
        long[] longs;
        try {
            longs = (long[]) arrayGetLongArrayMethod.invoke(array);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (IllegalArgumentException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        }
        ids = new Serializable[longs.length];
        for (int i = 0; i < ids.length; i++) {
            ids[i] = Long.valueOf(longs[i]);
        }
    } else {
        ids = (Serializable[]) array.getArray();
    }
    return ids;
}

From source file:org.wso2.carbon.dataservices.core.odata.RDBMSDataHandler.java

/**
 * This method bind values to prepared statement.
 *
 * @param type            data Type/*from   w w w. j ava2 s  . com*/
 * @param value           String value
 * @param ordinalPosition Ordinal Position
 * @param sqlStatement    Statement
 * @throws SQLException
 * @throws ParseException
 * @throws ODataServiceFault
 */
private void bindValuesToPreparedStatement(int type, String value, int ordinalPosition,
        PreparedStatement sqlStatement) throws SQLException, ParseException, ODataServiceFault {
    byte[] data;
    try {
        switch (type) {
        case Types.INTEGER:
            if (value == null) {
                sqlStatement.setNull(ordinalPosition, type);
            } else {
                sqlStatement.setInt(ordinalPosition, ConverterUtil.convertToInt(value));
            }
            break;
        case Types.TINYINT:
            if (value == null) {
                sqlStatement.setNull(ordinalPosition, type);
            } else {
                sqlStatement.setByte(ordinalPosition, ConverterUtil.convertToByte(value));
            }
            break;
        case Types.SMALLINT:
            if (value == null) {
                sqlStatement.setNull(ordinalPosition, type);
            } else {
                sqlStatement.setShort(ordinalPosition, ConverterUtil.convertToShort(value));
            }
            break;
        case Types.DOUBLE:
            if (value == null) {
                sqlStatement.setNull(ordinalPosition, type);
            } else {
                sqlStatement.setDouble(ordinalPosition, ConverterUtil.convertToDouble(value));
            }
            break;
        case Types.VARCHAR:
            /* fall through */
        case Types.CHAR:
            /* fall through */
        case Types.LONGVARCHAR:
            if (value == null) {
                sqlStatement.setNull(ordinalPosition, type);
            } else {
                sqlStatement.setString(ordinalPosition, value);
            }
            break;
        case Types.CLOB:
            if (value == null) {
                sqlStatement.setNull(ordinalPosition, type);
            } else {
                sqlStatement.setClob(ordinalPosition, new BufferedReader(new StringReader(value)),
                        value.length());
            }
            break;
        case Types.BOOLEAN:
            /* fall through */
        case Types.BIT:
            if (value == null) {
                sqlStatement.setNull(ordinalPosition, type);
            } else {
                sqlStatement.setBoolean(ordinalPosition, ConverterUtil.convertToBoolean(value));
            }
            break;
        case Types.BLOB:
            /* fall through */
        case Types.LONGVARBINARY:
            if (value == null) {
                sqlStatement.setNull(ordinalPosition, type);
            } else {
                data = this.getBytesFromBase64String(value);
                sqlStatement.setBlob(ordinalPosition, new ByteArrayInputStream(data), data.length);
            }
            break;
        case Types.BINARY:
            /* fall through */
        case Types.VARBINARY:
            if (value == null) {
                sqlStatement.setNull(ordinalPosition, type);
            } else {
                data = this.getBytesFromBase64String(value);
                sqlStatement.setBinaryStream(ordinalPosition, new ByteArrayInputStream(data), data.length);
            }
            break;
        case Types.DATE:
            if (value == null) {
                sqlStatement.setNull(ordinalPosition, type);
            } else {
                sqlStatement.setDate(ordinalPosition, DBUtils.getDate(value));
            }
            break;
        case Types.DECIMAL:
            /* fall through */
        case Types.NUMERIC:
            if (value == null) {
                sqlStatement.setNull(ordinalPosition, type);
            } else {
                sqlStatement.setBigDecimal(ordinalPosition, ConverterUtil.convertToBigDecimal(value));
            }
            break;
        case Types.FLOAT:
            /* fall through */
        case Types.REAL:
            if (value == null) {
                sqlStatement.setNull(ordinalPosition, type);
            } else {
                sqlStatement.setFloat(ordinalPosition, ConverterUtil.convertToFloat(value));
            }
            break;
        case Types.TIME:
            if (value == null) {
                sqlStatement.setNull(ordinalPosition, type);
            } else {
                sqlStatement.setTime(ordinalPosition, DBUtils.getTime(value));
            }
            break;
        case Types.LONGNVARCHAR:
            /* fall through */
        case Types.NCHAR:
            /* fall through */
        case Types.NVARCHAR:
            if (value == null) {
                sqlStatement.setNull(ordinalPosition, type);
            } else {
                sqlStatement.setNString(ordinalPosition, value);
            }
            break;
        case Types.NCLOB:
            if (value == null) {
                sqlStatement.setNull(ordinalPosition, type);
            } else {
                sqlStatement.setNClob(ordinalPosition, new BufferedReader(new StringReader(value)),
                        value.length());
            }
            break;
        case Types.BIGINT:
            if (value == null) {
                sqlStatement.setNull(ordinalPosition, type);
            } else {
                sqlStatement.setLong(ordinalPosition, ConverterUtil.convertToLong(value));
            }
            break;
        case Types.TIMESTAMP:
            if (value == null) {
                sqlStatement.setNull(ordinalPosition, type);
            } else {
                sqlStatement.setTimestamp(ordinalPosition, DBUtils.getTimestamp(value));
            }
            break;
        default:
            if (value == null) {
                sqlStatement.setNull(ordinalPosition, type);
            } else {
                sqlStatement.setString(ordinalPosition, value);
            }
            break;
        }
    } catch (DataServiceFault e) {
        throw new ODataServiceFault(e, "Error occurred while binding values. :" + e.getMessage());
    }
}

From source file:org.pentaho.platform.plugin.action.jfreereport.JFreeReportGeneratorComponent.java

public int getType(final Class typeClass) {
    if (typeClass != null) {
        if (typeClass.getName().equals(String.class.getName())) {
            return Types.VARCHAR;
        } else if (typeClass.getName().equals(BigDecimal.class.getName())
                || typeClass.getName().equals(Integer.class.getName())) {
            return Types.NUMERIC;
        } else if (typeClass.getName().equals(Date.class.getName())) {
            return Types.DATE;
        }//from  w w  w. ja  va 2  s . c  o  m
    }
    return Types.VARCHAR;
}

From source file:org.fastcatsearch.datasource.reader.DBReader.java

@Override
public SchemaSetting getAutoGeneratedSchemaSetting() {
    Map<String, String> properties = singleSourceConfig.getProperties();
    String jdbcSourceId = properties.get("jdbcSourceId");
    String dataSQL = properties.get("dataSQL");
    IRService service = ServiceManager.getInstance().getService(IRService.class);
    Connection con = null;//from  w w  w . j  ava  2  s.c om
    PreparedStatement pst = null;
    ResultSet res = null;
    ResultSetMetaData meta = null;
    try {
        JDBCSourceInfo jdbcInfo = service.getJDBCSourceInfo(jdbcSourceId);
        if (jdbcInfo != null) {
            con = getConnection(jdbcInfo);
        }
        logger.trace("get jdbc connection : {}", con);

        if (con != null) {
            logger.trace("executing sql :{}", dataSQL);
            pst = con.prepareStatement(dataSQL);
            pst.setFetchSize(1);
            pst.setMaxRows(1);
            res = pst.executeQuery();
            res.next();
            meta = res.getMetaData();

            SchemaSetting setting = new SchemaSetting();
            PrimaryKeySetting primaryKeySetting = new PrimaryKeySetting();
            List<FieldSetting> fieldSettingList = new ArrayList<FieldSetting>();
            List<AnalyzerSetting> analyzerSetting = new ArrayList<AnalyzerSetting>();
            List<GroupIndexSetting> groupIndexSetting = new ArrayList<GroupIndexSetting>();
            List<IndexSetting> indexSetting = new ArrayList<IndexSetting>();
            List<FieldIndexSetting> fieldIndexSetting = new ArrayList<FieldIndexSetting>();

            logger.trace("columnCount:{}", meta.getColumnCount());

            String tableName = null;

            for (int inx = 0; inx < meta.getColumnCount(); inx++) {
                if (tableName == null) {
                    tableName = meta.getTableName(inx + 1);
                }
                FieldSetting field = new FieldSetting();
                Type type = null;
                int size = 0;
                switch (meta.getColumnType(inx + 1)) {
                case Types.INTEGER:
                case Types.TINYINT:
                case Types.SMALLINT:
                case Types.NUMERIC:
                    type = Type.INT;
                    break;
                case Types.BIGINT:
                    type = Type.LONG;
                    break;
                case Types.FLOAT:
                    type = Type.FLOAT;
                    break;
                case Types.DOUBLE:
                    type = Type.DOUBLE;
                    break;
                case Types.DATE:
                case Types.TIME:
                case Types.TIMESTAMP:
                    type = Type.DATETIME;
                    break;
                case Types.CHAR:
                case Types.VARCHAR:
                case Types.LONGVARCHAR:
                    type = Type.STRING;
                    break;
                default:
                    type = Type.STRING;
                    break;
                }
                field.setId(meta.getColumnLabel(inx + 1));
                field.setName(field.getId());
                field.setType(type);
                field.setSize(size);
                logger.trace("field add {}", field);
                fieldSettingList.add(field);
            }

            setting.setFieldSettingList(fieldSettingList);
            setting.setPrimaryKeySetting(primaryKeySetting);
            setting.setFieldIndexSettingList(fieldIndexSetting);
            setting.setAnalyzerSettingList(analyzerSetting);
            setting.setGroupIndexSettingList(groupIndexSetting);
            setting.setIndexSettingList(indexSetting);

            return setting;
        }
    } catch (IRException e) {
        logger.error("", e);
    } catch (SQLException e) {
        logger.error("", e);
    } finally {
        if (res != null)
            try {
                res.close();
            } catch (SQLException ignore) {
            }
        if (pst != null)
            try {
                pst.close();
            } catch (SQLException ignore) {
            }
        if (con != null)
            try {
                con.close();
            } catch (SQLException ignore) {
            }
    }
    return null;
}

From source file:com.splicemachine.db.impl.sql.compile.QueryTreeNode.java

/**
 * Get a ConstantNode to represent a typed null value.
 *
 * @param type Type of the null node./*from w  w w . jav  a2  s. co m*/
 * @throws StandardException Thrown on error
 * @return A ConstantNode with the specified type, and a value of null
 */
public ConstantNode getNullNode(DataTypeDescriptor type) throws StandardException {
    int constantNodeType;
    switch (type.getTypeId().getJDBCTypeId()) {
    case Types.VARCHAR:
        constantNodeType = C_NodeTypes.VARCHAR_CONSTANT_NODE;
        break;
    case Types.CHAR:
        constantNodeType = C_NodeTypes.CHAR_CONSTANT_NODE;
        break;
    case Types.TINYINT:
        constantNodeType = C_NodeTypes.TINYINT_CONSTANT_NODE;
        break;
    case Types.SMALLINT:
        constantNodeType = C_NodeTypes.SMALLINT_CONSTANT_NODE;
        break;
    case Types.INTEGER:
        constantNodeType = C_NodeTypes.INT_CONSTANT_NODE;
        break;
    case Types.BIGINT:
        constantNodeType = C_NodeTypes.LONGINT_CONSTANT_NODE;
        break;
    case Types.REAL:
        constantNodeType = C_NodeTypes.FLOAT_CONSTANT_NODE;
        break;
    case Types.DOUBLE:
        constantNodeType = C_NodeTypes.DOUBLE_CONSTANT_NODE;
        break;
    case Types.NUMERIC:
    case Types.DECIMAL:
        constantNodeType = C_NodeTypes.DECIMAL_CONSTANT_NODE;
        break;
    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
        constantNodeType = C_NodeTypes.USERTYPE_CONSTANT_NODE;
        break;
    case Types.BINARY:
        constantNodeType = C_NodeTypes.BIT_CONSTANT_NODE;
        break;
    case Types.VARBINARY:
        constantNodeType = C_NodeTypes.VARBIT_CONSTANT_NODE;
        break;
    case Types.LONGVARCHAR:
        constantNodeType = C_NodeTypes.LONGVARCHAR_CONSTANT_NODE;
        break;
    case Types.CLOB:
        constantNodeType = C_NodeTypes.CLOB_CONSTANT_NODE;
        break;
    case Types.LONGVARBINARY:
        constantNodeType = C_NodeTypes.LONGVARBIT_CONSTANT_NODE;
        break;
    case Types.BLOB:
        constantNodeType = C_NodeTypes.BLOB_CONSTANT_NODE;
        break;
    case JDBC40Translation.SQLXML:
        constantNodeType = C_NodeTypes.XML_CONSTANT_NODE;
        break;
    case Types.BOOLEAN:
        constantNodeType = C_NodeTypes.BOOLEAN_CONSTANT_NODE;
        break;
    default:
        if (type.getTypeId().userType()) {
            constantNodeType = C_NodeTypes.USERTYPE_CONSTANT_NODE;
        } else {
            throw StandardException.newException(SQLState.LANG_NONULL_DATATYPE,
                    type.getTypeId().getSQLTypeName());
        }
    }

    ConstantNode constantNode = (ConstantNode) getNodeFactory().getNode(constantNodeType, type.getTypeId(), cm);

    constantNode.setType(type.getNullabilityType(true));

    return constantNode;
}