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:lasige.steeldb.jdbc.BFTRowSet.java

/**
 * Converts the given <code>Object</code> in the Java programming language
 * to the standard mapping for the specified SQL target data type.
 * The conversion must be to a string or numeric type, but there are no
 * restrictions on the type to be converted.  If the source type and target
 * type are the same, the given object is simply returned.
 *
 * @param srcObj the <code>Object</code> in the Java programming language
 *               that is to be converted to the target type
 * @param srcType the data type that is the standard mapping in SQL of the
 *                object to be converted; must be one of the constants in
 *                <code>java.sql.Types</code>
 * @param trgType the SQL data type to which to convert the given object;
 *                must be one of the following constants in
 *                <code>java.sql.Types</code>: <code>NUMERIC</code>,
 *         <code>DECIMAL</code>, <code>BIT</code>, <code>TINYINT</code>,
 *         <code>SMALLINT</code>, <code>INTEGER</code>, <code>BIGINT</code>,
 *         <code>REAL</code>, <code>DOUBLE</code>, <code>FLOAT</code>,
 *         <code>VARCHAR</code>, <code>LONGVARCHAR</code>, or <code>CHAR</code>
 * @return an <code>Object</code> value.that is
 *         the standard object mapping for the target SQL type
 * @throws SQLException if the given target type is not one of the string or
 *         numeric types in <code>java.sql.Types</code>
 *///from   w  w  w .j  ava  2s  . c om
private Object convertNumeric(Object srcObj, int srcType, int trgType) throws SQLException {

    if (srcType == trgType) {
        return srcObj;
    }

    if (isNumeric(trgType) == false && isString(trgType) == false) {
        throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.dtypemismt").toString() + trgType);
    }

    try {
        switch (trgType) {
        case java.sql.Types.BIT:
            Integer i = new Integer(srcObj.toString().trim());
            return i.equals(new Integer((int) 0)) ? new Boolean(false) : new Boolean(true);
        case java.sql.Types.TINYINT:
            return new Byte(srcObj.toString().trim());
        case java.sql.Types.SMALLINT:
            return new Short(srcObj.toString().trim());
        case java.sql.Types.INTEGER:
            return new Integer(srcObj.toString().trim());
        case java.sql.Types.BIGINT:
            return new Long(srcObj.toString().trim());
        case java.sql.Types.NUMERIC:
        case java.sql.Types.DECIMAL:
            return new BigDecimal(srcObj.toString().trim());
        case java.sql.Types.REAL:
        case java.sql.Types.FLOAT:
            return new Float(srcObj.toString().trim());
        case java.sql.Types.DOUBLE:
            return new Double(srcObj.toString().trim());
        case java.sql.Types.CHAR:
        case java.sql.Types.VARCHAR:
        case java.sql.Types.LONGVARCHAR:
            return new String(srcObj.toString());
        default:
            throw new SQLException(
                    resBundle.handleGetObject("cachedrowsetimpl.dtypemismt").toString() + trgType);
        }
    } catch (NumberFormatException ex) {
        throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.dtypemismt").toString() + trgType);
    }
}

From source file:lasige.steeldb.jdbc.BFTRowSet.java

/**
 * Sets the designated column in either the current row or the insert
 * row of this <code>CachedRowSetImpl</code> object with the given
 * <code>float</code> value.
 * <P>/*from www.ja  v  a 2  s  .  co m*/
 * This method updates a column value in the current row or the insert
 * row of this rowset, but it does not update the database.
 * If the cursor is on a row in the rowset, the
 * method {@link #updateRow} must be called to update the database.
 * If the cursor is on the insert row, the method {@link #insertRow}
 * must be called, which will insert the new row into both this rowset
 * and the database. Both of these methods must be called before the
 * cursor moves to another row.
 *
 * @param columnIndex the first column is <code>1</code>, the second
 *        is <code>2</code>, and so on; must be <code>1</code> or larger
 *        and equal to or less than the number of columns in this rowset
 * @param x the new column value
 * @throws SQLException if (1) the given column index is out of bounds,
 *            (2) the cursor is not on one of this rowset's rows or its
 *            insert row, or (3) this rowset is
 *            <code>ResultSet.CONCUR_READ_ONLY</code>
 */
public void updateFloat(int columnIndex, float x) throws SQLException {
    // sanity check.
    checkIndex(columnIndex);
    // make sure the cursor is on a valid row
    checkCursor();

    Object obj = convertNumeric(new Float(x), java.sql.Types.REAL, RowSetMD.getColumnType(columnIndex));

    getCurrentRow().setColumnObject(columnIndex, obj);
}