Example usage for java.sql Types BIT

List of usage examples for java.sql Types BIT

Introduction

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

Prototype

int BIT

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

Click Source Link

Document

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

Usage

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

/**
 * Indicates whether the given SQL data type is a boolean type.
 * This method is called internally by the conversion methods
 * <code>convertNumeric</code> and <code>convertBoolean</code>.
 *
 * @param type one of the constants from <code>java.sql.Types</code>
 * @return <code>true</code> if the given type is <code>BIT</code>,
 *         , or <code>BOOLEAN</code>;
 *         <code>false</code> otherwise
 *//*  w w  w . j  av a  2s.  c  o  m*/
private boolean isBoolean(int type) {
    switch (type) {
    case java.sql.Types.BIT:
    case java.sql.Types.BOOLEAN:
        return true;
    default:
        return false;
    }
}

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>
 *///  ww  w.ja v  a  2  s.  co m
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

/**
 * 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>BIT</code>,
 *         or <code>BOOLEAN</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 Boolean
 *         types in <code>java.sql.Types</code>
 *//*  w ww.  j a va 2  s .  co m*/
private Object convertBoolean(Object srcObj, int srcType, int trgType) throws SQLException {

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

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

    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.BOOLEAN:
            return new Boolean(srcObj.toString().trim());
        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>boolean</code> value.
 * <P>/*w w w  . jav  a  2  s  .  c  o  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 updateBoolean(int columnIndex, boolean x) throws SQLException {
    // sanity check.
    checkIndex(columnIndex);
    // make sure the cursor is on a valid row
    checkCursor();
    Object obj = convertBoolean(new Boolean(x), java.sql.Types.BIT, RowSetMD.getColumnType(columnIndex));

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