Example usage for java.sql Types REAL

List of usage examples for java.sql Types REAL

Introduction

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

Prototype

int REAL

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

Click Source Link

Document

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

Usage

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;// ww w  .j  av a2s . 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;
}

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

/**
 * Return the {@link Types} constant for the given SQL type name.
 *//*from w  w w.ja  va 2s.  c om*/
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.ddlutils.platform.mssql.MSSqlBuilder.java

/**
 * {@inheritDoc}/*from w  w  w .j a  v  a2 s.  com*/
 */
protected String getValueAsString(Column column, Object value) {
    if (value == null) {
        return "NULL";
    }

    StringBuffer result = new StringBuffer();

    switch (column.getTypeCode()) {
    case Types.REAL:
    case Types.NUMERIC:
    case Types.FLOAT:
    case Types.DOUBLE:
    case Types.DECIMAL:
        // SQL Server does not want quotes around the value
        if (!(value instanceof String) && (getValueNumberFormat() != null)) {
            result.append(getValueNumberFormat().format(value));
        } else {
            result.append(value.toString());
        }
        break;
    case Types.DATE:
        result.append("CAST(");
        result.append(getPlatformInfo().getValueQuoteToken());
        result.append(value instanceof String ? (String) value : getValueDateFormat().format(value));
        result.append(getPlatformInfo().getValueQuoteToken());
        result.append(" AS datetime)");
        break;
    case Types.TIME:
        result.append("CAST(");
        result.append(getPlatformInfo().getValueQuoteToken());
        result.append(value instanceof String ? (String) value : getValueTimeFormat().format(value));
        result.append(getPlatformInfo().getValueQuoteToken());
        result.append(" AS datetime)");
        break;
    case Types.TIMESTAMP:
        result.append("CAST(");
        result.append(getPlatformInfo().getValueQuoteToken());
        result.append(value.toString());
        result.append(getPlatformInfo().getValueQuoteToken());
        result.append(" AS datetime)");
        break;
    }
    return super.getValueAsString(column, value);
}

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.
 *///ww w .  j  a  v a 2 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:com.opencsv.ResultSetHelperService.java

private String getColumnValue(ResultSet rs, int colType, int colIndex, boolean trim, String dateFormatString,
        String timestampFormatString) throws SQLException, IOException {

    String value = "";

    switch (colType) {
    case Types.BIT:
    case Types.JAVA_OBJECT:
        // Once Java 7 is the minimum supported version.
        //            value = Objects.toString(rs.getObject(colIndex), "");
        value = ObjectUtils.toString(rs.getObject(colIndex), "");
        break;//from   www. ja  va2s .co m
    case Types.BOOLEAN:
        // Once Java 7 is the minimum supported version.
        //            value = Objects.toString(rs.getBoolean(colIndex));
        value = ObjectUtils.toString(rs.getBoolean(colIndex));
        break;
    case Types.NCLOB: // todo : use rs.getNClob
    case Types.CLOB:
        Clob c = rs.getClob(colIndex);
        if (c != null) {
            StrBuilder sb = new StrBuilder();
            sb.readFrom(c.getCharacterStream());
            value = sb.toString();
        }
        break;
    case Types.BIGINT:
        // Once Java 7 is the minimum supported version.
        //            value = Objects.toString(rs.getLong(colIndex));
        value = ObjectUtils.toString(rs.getLong(colIndex));
        break;
    case Types.DECIMAL:
    case Types.REAL:
    case Types.NUMERIC:
        // Once Java 7 is the minimum supported version.
        //            value = Objects.toString(rs.getBigDecimal(colIndex), "");
        value = ObjectUtils.toString(rs.getBigDecimal(colIndex), "");
        break;
    case Types.DOUBLE:
        // Once Java 7 is the minimum supported version.
        //            value = Objects.toString(rs.getDouble(colIndex));
        value = ObjectUtils.toString(rs.getDouble(colIndex));
        break;
    case Types.FLOAT:
        // Once Java 7 is the minimum supported version.
        //            value = Objects.toString(rs.getFloat(colIndex));
        value = ObjectUtils.toString(rs.getFloat(colIndex));
        break;
    case Types.INTEGER:
    case Types.TINYINT:
    case Types.SMALLINT:
        // Once Java 7 is the minimum supported version.
        //            value = Objects.toString(rs.getInt(colIndex));
        value = ObjectUtils.toString(rs.getInt(colIndex));
        break;
    case Types.DATE:
        java.sql.Date date = rs.getDate(colIndex);
        if (date != null) {
            SimpleDateFormat df = new SimpleDateFormat(dateFormatString);
            value = df.format(date);
        }
        break;
    case Types.TIME:
        // Once Java 7 is the minimum supported version.
        //            value = Objects.toString(rs.getTime(colIndex), "");
        value = ObjectUtils.toString(rs.getTime(colIndex), "");
        break;
    case Types.TIMESTAMP:
        value = handleTimestamp(rs.getTimestamp(colIndex), timestampFormatString);
        break;
    case Types.NVARCHAR: // todo : use rs.getNString
    case Types.NCHAR: // todo : use rs.getNString
    case Types.LONGNVARCHAR: // todo : use rs.getNString
    case Types.LONGVARCHAR:
    case Types.VARCHAR:
    case Types.CHAR:
        String columnValue = rs.getString(colIndex);
        if (trim && columnValue != null) {
            value = columnValue.trim();
        } else {
            value = columnValue;
        }
        break;
    default:
        value = "";
    }

    if (rs.wasNull() || value == null) {
        value = "";
    }

    return value;
}

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

/**
 * Creates a new model reader instance./*www.  j  a v  a2  s .  co  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.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;//w ww.  ja v a 2s.c om
    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));
        }
    }
}

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:/*from  w  w  w  .j  a  v  a 2 s  .c  om*/
        return java.sql.Timestamp.class;
    default:
        return Object.class;
    }
}

From source file:org.jumpmind.db.platform.AbstractJdbcDdlReader.java

public AbstractJdbcDdlReader(IDatabasePlatform platform) {
    this.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();/* www .j av a 2 s.c  o  m*/
    _columnsForFK = initColumnsForFK();
    _columnsForIndex = initColumnsForIndex();

    initWildcardString(platform);
}