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:architecture.ee.web.community.page.dao.jdbc.JdbcPageDao.java

/**
 *  ? ?/*from   www.j a v  a  2 s .com*/
 */
public void create(Page page) {

    long nextPageId = getNextId(sequencerName);
    page.setPageId(nextPageId);
    page.setVersionId(DEFAULT_PAGE_VERSION);

    // binary body data handleing

    String tempPrefix = ApplicationHelper.getApplicationProperty("components.page.temporaryPagePrefix",
            "tempPAGE-");
    if (page.getName() == null || page.getName().startsWith(tempPrefix)) {
        page.setName((new StringBuilder())
                .append(ApplicationHelper.getApplicationProperty("components.page.pagePrefix", "PAGE-"))
                .append(nextPageId).toString());
    }

    // INSERT V2_PAGE
    getExtendedJdbcTemplate().update(getBoundSql("ARCHITECTURE_COMMUNITY.CREATE_PAGE").getSql(),
            new SqlParameterValue(Types.NUMERIC, page.getPageId()),
            new SqlParameterValue(Types.NUMERIC, page.getObjectType()),
            new SqlParameterValue(Types.NUMERIC, page.getObjectId()),
            new SqlParameterValue(Types.VARCHAR, page.getName()),
            new SqlParameterValue(Types.NUMERIC, page.getVersionId()),
            new SqlParameterValue(Types.NUMERIC, page.getUser().getUserId()),
            new SqlParameterValue(Types.TIMESTAMP, page.getCreationDate()),
            new SqlParameterValue(Types.TIMESTAMP, page.getModifiedDate()));

    insertPageVersion(page);

    insertPageBody(page);

    insertProperties(page);
}

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

/**
 * Derive a default SQL type from the given Java type.
 * @param javaType the Java type to translate
 * @return the corresponding SQL type, or {@link SqlTypeValue#TYPE_UNKNOWN} if none found
 *//*from w w w  . j av  a  2s.  co m*/
public static int javaTypeToSqlParameterType(@Nullable Class<?> javaType) {
    if (javaType == null) {
        return SqlTypeValue.TYPE_UNKNOWN;
    }
    Integer sqlType = javaTypeToSqlTypeMap.get(javaType);
    if (sqlType != null) {
        return sqlType;
    }
    if (Number.class.isAssignableFrom(javaType)) {
        return Types.NUMERIC;
    }
    if (isStringValue(javaType)) {
        return Types.VARCHAR;
    }
    if (isDateValue(javaType) || Calendar.class.isAssignableFrom(javaType)) {
        return Types.TIMESTAMP;
    }
    return SqlTypeValue.TYPE_UNKNOWN;
}

From source file:co.nubetech.hiho.mapreduce.lib.db.apache.DataDrivenDBInputFormat.java

/**
 * @return the DBSplitter implementation to use to divide the table/query into InputSplits.
 *///from w  w w . jav  a2 s.  c o  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:
        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:architecture.ee.web.community.timeline.dao.jdbc.JdbcTimelineDao.java

public void updateTimeline(Timeline timeline) {
    long timelineIdToUse = timeline.getTimelineId();
    if (timelineIdToUse < 1) {
        timelineIdToUse = nextId();/*from   www.ja  va  2 s . c o  m*/
        ((DefaultTimeline) timeline).setTimelineId(timelineIdToUse);
        getJdbcTemplate().update(getBoundSql("ARCHITECTURE_COMMUNITY.INSERT_TIMELINE").getSql(),
                new SqlParameterValue(Types.NUMERIC, timelineIdToUse),
                new SqlParameterValue(Types.NUMERIC, timeline.getObjectType()),
                new SqlParameterValue(Types.NUMERIC, timeline.getObjectId()),
                new SqlParameterValue(Types.VARCHAR, timeline.getHeadline()),
                new SqlParameterValue(Types.VARCHAR, timeline.getBody()),
                new SqlParameterValue(Types.DATE, timeline.getStartDate()),
                new SqlParameterValue(Types.DATE, timeline.getEndDate()),
                new SqlParameterValue(Types.VARCHAR,
                        timeline.isHasMedia() ? null : timeline.getMedia().getUrl()),
                new SqlParameterValue(Types.VARCHAR,
                        timeline.isHasMedia() ? null : timeline.getMedia().getCaption()),
                new SqlParameterValue(Types.VARCHAR,
                        timeline.isHasMedia() ? null : timeline.getMedia().getCredit()),
                new SqlParameterValue(Types.VARCHAR,
                        timeline.isHasMedia() ? null : timeline.getMedia().getThumbnailUrl()));
    } else {
        getJdbcTemplate().update(getBoundSql("ARCHITECTURE_COMMUNITY.UPDATE_TIMELINE").getSql(),
                new SqlParameterValue(Types.VARCHAR, timeline.getHeadline()),
                new SqlParameterValue(Types.VARCHAR, timeline.getBody()),
                new SqlParameterValue(Types.DATE, timeline.getStartDate()),
                new SqlParameterValue(Types.DATE, timeline.getEndDate()),
                new SqlParameterValue(Types.VARCHAR,
                        timeline.isHasMedia() ? null : timeline.getMedia().getUrl()),
                new SqlParameterValue(Types.VARCHAR,
                        timeline.isHasMedia() ? null : timeline.getMedia().getCaption()),
                new SqlParameterValue(Types.VARCHAR,
                        timeline.isHasMedia() ? null : timeline.getMedia().getCredit()),
                new SqlParameterValue(Types.VARCHAR,
                        timeline.isHasMedia() ? null : timeline.getMedia().getThumbnailUrl()),
                new SqlParameterValue(Types.NUMERIC, timeline.getTimelineId()));
    }
}

From source file:wzw.sql.ResultSetConverter.java

/**
 * ?//from  w  w  w .java2 s . c  o m
 * @param rs
 * @param type Listjava.sql.Types 
 * @return
 * @throws SQLException
 */
public static List<Object> toTypeList(ResultSet rs, int type) throws SQLException {

    List<Object> list = new ArrayList<Object>();

    switch (type) {
    case Types.INTEGER:
        while (rs.next()) {
            list.add(new Integer(rs.getInt(1)));
        }

    case Types.BIGINT:
        while (rs.next()) {
            list.add(new Long(rs.getLong(1)));
        }

    case Types.VARCHAR:
        while (rs.next()) {
            list.add(rs.getString(1));
        }

    case Types.FLOAT:
        while (rs.next()) {
            list.add(new Float(rs.getFloat(1)));
        }

    case Types.DECIMAL:
    case Types.DOUBLE:
    case Types.NUMERIC:
        while (rs.next()) {
            list.add(new Double(rs.getDouble(1)));
        }

    case Types.TIMESTAMP:
        while (rs.next()) {
            list.add(rs.getTimestamp(1));
        }

    case Types.DATE:
        while (rs.next()) {
            list.add(rs.getDate(1));
        }

    case Types.TIME:
        while (rs.next()) {
            list.add(rs.getTime(1));
        }

        //default:
    }
    return list;
}

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

/**
 * Return the {@link Types} constant for the given SQL type name.
 *///  w w w  . ja v  a  2s  .  co  m
public static int getJDBCType(String name) {
    if ("array".equalsIgnoreCase(name))
        return Types.ARRAY;
    if ("bigint".equalsIgnoreCase(name))
        return Types.BIGINT;
    if ("binary".equalsIgnoreCase(name))
        return Types.BINARY;
    if ("bit".equalsIgnoreCase(name))
        return Types.BIT;
    if ("blob".equalsIgnoreCase(name))
        return Types.BLOB;
    if ("char".equalsIgnoreCase(name))
        return Types.CHAR;
    if ("clob".equalsIgnoreCase(name))
        return Types.CLOB;
    if ("date".equalsIgnoreCase(name))
        return Types.DATE;
    if ("decimal".equalsIgnoreCase(name))
        return Types.DECIMAL;
    if ("distinct".equalsIgnoreCase(name))
        return Types.DISTINCT;
    if ("double".equalsIgnoreCase(name))
        return Types.DOUBLE;
    if ("float".equalsIgnoreCase(name))
        return Types.FLOAT;
    if ("integer".equalsIgnoreCase(name))
        return Types.INTEGER;
    if ("java_object".equalsIgnoreCase(name))
        return Types.JAVA_OBJECT;
    if ("longvarbinary".equalsIgnoreCase(name))
        return Types.LONGVARBINARY;
    if ("longvarchar".equalsIgnoreCase(name))
        return Types.LONGVARCHAR;
    if ("null".equalsIgnoreCase(name))
        return Types.NULL;
    if ("numeric".equalsIgnoreCase(name))
        return Types.NUMERIC;
    if ("other".equalsIgnoreCase(name))
        return Types.OTHER;
    if ("real".equalsIgnoreCase(name))
        return Types.REAL;
    if ("ref".equalsIgnoreCase(name))
        return Types.REF;
    if ("smallint".equalsIgnoreCase(name))
        return Types.SMALLINT;
    if ("struct".equalsIgnoreCase(name))
        return Types.STRUCT;
    if ("time".equalsIgnoreCase(name))
        return Types.TIME;
    if ("timestamp".equalsIgnoreCase(name))
        return Types.TIMESTAMP;
    if ("tinyint".equalsIgnoreCase(name))
        return Types.TINYINT;
    if ("varbinary".equalsIgnoreCase(name))
        return Types.VARBINARY;
    if ("varchar".equalsIgnoreCase(name))
        return Types.VARCHAR;
    if (name == null || name.toLowerCase().startsWith("unknown"))
        return Types.OTHER;
    throw new IllegalArgumentException("name = " + name);
}

From source file:org.apache.tajo.storage.jdbc.JdbcMetadataProviderBase.java

private TypeDesc convertDataType(ResultSet res) throws SQLException {
    final int typeId = res.getInt("DATA_TYPE");

    switch (typeId) {
    case Types.BOOLEAN:
        return new TypeDesc(newSimpleDataType(Type.BOOLEAN));

    case Types.TINYINT:
    case Types.SMALLINT:
    case Types.INTEGER:
        return new TypeDesc(newSimpleDataType(Type.INT4));

    case Types.DISTINCT: // sequence for postgresql
    case Types.BIGINT:
        return new TypeDesc(newSimpleDataType(Type.INT8));

    case Types.FLOAT:
        return new TypeDesc(newSimpleDataType(Type.FLOAT4));

    case Types.NUMERIC:
    case Types.DECIMAL:
    case Types.DOUBLE:
        return new TypeDesc(newSimpleDataType(Type.FLOAT8));

    case Types.DATE:
        return new TypeDesc(newSimpleDataType(Type.DATE));

    case Types.TIME:
        return new TypeDesc(newSimpleDataType(Type.TIME));

    case Types.TIMESTAMP:
        return new TypeDesc(newSimpleDataType(Type.TIMESTAMP));

    case Types.CHAR:
    case Types.NCHAR:
    case Types.VARCHAR:
    case Types.NVARCHAR:
    case Types.CLOB:
    case Types.NCLOB:
    case Types.LONGVARCHAR:
    case Types.LONGNVARCHAR:
        return new TypeDesc(newSimpleDataType(Type.TEXT));

    case Types.BINARY:
    case Types.VARBINARY:
    case Types.BLOB:
        return new TypeDesc(newSimpleDataType(Type.BLOB));

    default:/*ww  w  .ja  v a 2 s . c  om*/
        throw SQLExceptionUtil.toSQLException(new UnsupportedDataTypeException(typeId + ""));
    }
}

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

/**
 * Save a new configuration channel./*from  w  w  w.j  a  v a  2s .co m*/
 * Note, this method uses a stored procedure, so it must be used for all newly
 * created configuration channels.
 * @param channel The channel object to persist.
 */
public static void saveNewConfigChannel(ConfigChannel channel) {
    CallableMode m = ModeFactory.getCallableMode("config_queries", "create_new_config_channel");
    Map inParams = new HashMap();
    Map outParams = new HashMap();

    inParams.put("org_id_in", channel.getOrgId());
    inParams.put("type_in", channel.getConfigChannelType().getLabel());
    inParams.put("name_in", channel.getName());
    inParams.put("label_in", channel.getLabel());
    inParams.put("description_in", channel.getDescription());
    //Outparam
    outParams.put("channelId", new Integer(Types.NUMERIC));

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

    Long channelId = (Long) result.get("channelId");
    channel.setId(channelId);
}

From source file:com.glaf.core.jdbc.QueryHelper.java

@SuppressWarnings("unchecked")
public List<ColumnDefinition> getColumnDefinitions(String systemName, String sql, Map<String, Object> params) {
    SqlExecutor sqlExecutor = DBUtils.replaceSQL(sql, params);
    Connection conn = null;//from w w  w  . java2  s. com
    PreparedStatement psmt = null;
    ResultSet rs = null;
    ResultSetMetaData rsmd = null;
    try {
        conn = DBConnectionFactory.getConnection(systemName);
        psmt = conn.prepareStatement(sqlExecutor.getSql());
        if (sqlExecutor.getParameter() != null) {
            List<Object> values = (List<Object>) sqlExecutor.getParameter();
            JdbcUtils.fillStatement(psmt, values);
        }
        rs = psmt.executeQuery();
        rsmd = rs.getMetaData();
        int count = rsmd.getColumnCount();
        List<ColumnDefinition> columns = new ArrayList<ColumnDefinition>();
        for (int index = 1; index <= count; index++) {
            int sqlType = rsmd.getColumnType(index);
            ColumnDefinition column = new ColumnDefinition();
            column.setIndex(index);
            column.setColumnName(rsmd.getColumnName(index));
            column.setColumnLabel(rsmd.getColumnLabel(index));
            column.setJavaType(FieldType.getJavaType(sqlType));
            column.setPrecision(rsmd.getPrecision(index));
            column.setScale(rsmd.getScale(index));
            if (column.getScale() == 0 && sqlType == Types.NUMERIC) {
                column.setJavaType("Long");
            }
            column.setName(StringTools.camelStyle(column.getColumnLabel().toLowerCase()));
            columns.add(column);
        }
        return columns;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    } finally {
        JdbcUtils.close(rs);
        JdbcUtils.close(psmt);
        JdbcUtils.close(conn);
    }
}

From source file:madgik.exareme.master.queryProcessor.analyzer.stat.Stat.java

private int computeColumnSize(String columnName, int columnType, String table_sample) throws Exception {
    int columnSize = 0;
    if (columnType == Types.INTEGER || columnType == Types.REAL || columnType == Types.DOUBLE
            || columnType == Types.DECIMAL || columnType == Types.FLOAT || columnType == Types.NUMERIC) {
        columnSize = NUM_SIZE;/*from www. ja v  a2 s  . c o m*/
    } else if (columnType == Types.VARCHAR) {
        String query0 = "select max(length(`" + columnName + "`)) as length from (select `" + columnName
                + "` from `" + table_sample + "`)" + " where `" + columnName + "` is not null limit "
                + MAX_STRING_SAMPLE;

        Statement stmt0 = con.createStatement();
        ResultSet rs0 = stmt0.executeQuery(query0);

        while (rs0.next()) {
            columnSize = rs0.getInt("length");
        }
        rs0.close();
        stmt0.close();

    } else if (columnType == Types.BLOB)
        columnSize = BLOB_SIZE;

    return columnSize;
}