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:org.jumpmind.db.platform.AbstractJdbcDdlReader.java

protected List<MetaDataColumnDescriptor> initColumnsForIndex() {
    List<MetaDataColumnDescriptor> result = new ArrayList<MetaDataColumnDescriptor>();

    result.add(new MetaDataColumnDescriptor("INDEX_NAME", Types.VARCHAR));
    // we're also reading the table name so that a model reader impl can
    // filter manually
    result.add(new MetaDataColumnDescriptor("TABLE_NAME", Types.VARCHAR));
    result.add(new MetaDataColumnDescriptor("NON_UNIQUE", Types.BIT, Boolean.TRUE));
    result.add(new MetaDataColumnDescriptor("ORDINAL_POSITION", Types.TINYINT, new Short((short) 0)));
    result.add(new MetaDataColumnDescriptor("COLUMN_NAME", Types.VARCHAR));
    result.add(new MetaDataColumnDescriptor("TYPE", Types.TINYINT));
    return result;
}

From source file:org.vivoweb.harvester.util.DatabaseClone.java

/**
 * Clone a database/*  w  ww .j  av  a 2  s . c  o m*/
 * @throws SQLException error connecting
 * @throws DatabaseUnitException error
 * @throws IOException error resolving connections
 */
public void execute() throws SQLException, DatabaseUnitException, IOException {
    String[] tableTypes = new String[] { "TABLE" };
    if (this.dbUnitFeatures != null) {
        for (String feature : this.dbUnitFeatures.keySet()) {
            if (feature.trim().equals("http://www.dbunit.org/properties/tableType")) {
                tableTypes = this.dbUnitFeatures.get(feature).toString().split(",");
            }
        }
    }
    IDataSet data = getDataSet();
    if (this.db2 != null) {
        log.info("Preparing Output Database");
        Connection db1conn = this.db1.getConnection();
        Connection db2conn = this.db2.getConnection();
        Map<Integer, Map<String, String>> inputDbTypes = getDbTypes(db1conn, "input");
        Map<Integer, Map<String, String>> outputDbTypes = getDbTypes(db2conn, "output");
        ResultSet tableData = db2conn.getMetaData().getTables(db2conn.getCatalog(), null, "%", tableTypes);
        while (tableData.next()) {
            String db2tableName = tableData.getString("TABLE_NAME");
            for (String db1table : data.getTableNames()) {
                if (db1table.trim().equalsIgnoreCase(db2tableName.trim())) {
                    log.debug("Droping table '" + db2tableName + "' from output database");
                    String sql = "DROP TABLE " + db2tableName;
                    log.trace("Drop Table SQL Query:\n" + sql);
                    db2conn.createStatement().executeUpdate(sql);
                }
            }
        }
        for (String table : data.getTableNames()) {
            // get record set
            log.debug("Creating table '" + table + "' in output database");
            ResultSet columnRS = db1conn.getMetaData().getColumns(null, null, table, null);
            int count = 0;
            StringBuilder createTableSB = new StringBuilder();
            createTableSB.append("CREATE TABLE " + table + " (");
            while (columnRS.next()) {
                if (columnRS.getString("TABLE_NAME").equals(table)) {
                    String colName = columnRS.getString("COLUMN_NAME");
                    log.debug("Getting column information for '" + colName + "'");
                    Integer typeCode = Integer.valueOf(columnRS.getInt("DATA_TYPE"));
                    int size = columnRS.getInt("COLUMN_SIZE");
                    if (!outputDbTypes.containsKey(typeCode)) {
                        if (typeCode.intValue() == Types.BIT) {
                            typeCode = Integer.valueOf(Types.BOOLEAN);
                            size = 0;
                        } else { //TODO: more type conversion issues possible, make this if/else more exhaustive
                            if (inputDbTypes.containsKey(typeCode)) {
                                log.warn("Output database does not support datatype '"
                                        + inputDbTypes.get(typeCode).get("TYPE_NAME") + "': using VARCHAR");
                            } else {
                                log.error("Unknown datatype code '" + typeCode + "': using VARCHAR");
                            }
                            typeCode = Integer.valueOf(Types.VARCHAR);
                        }
                    } else {
                        //                     log.trace("typeCode: "+typeCode);
                    }
                    Map<String, String> map = outputDbTypes.get(typeCode);
                    String typeName = map.get("TYPE_NAME");
                    String params = map.get("CREATE_PARAMS");
                    if (StringUtils.isBlank(params)) {
                        params = map.get("PARAMS");
                    }
                    boolean needParam = (StringUtils.isNotBlank(params) && (size != 0));
                    //                  log.trace("column '"+colName+"': "+typeCode+" => '"+typeName+((needParam)?"("+size+")":"")+"'");
                    if (count != 0) {
                        createTableSB.append(',');
                    }
                    createTableSB.append("\n  ");
                    createTableSB.append(colName);
                    createTableSB.append(" ");
                    createTableSB.append(typeName);
                    if (needParam) {
                        createTableSB.append("(");
                        createTableSB.append(size);
                        createTableSB.append(")");
                    }
                    count++;
                }
            }
            createTableSB.append("\n)");
            log.trace("Create Table SQL Query:\n" + createTableSB);
            db2conn.createStatement().executeUpdate(createTableSB.toString());
        }
        log.info("Dumping Dataset To Output");
        DatabaseOperation.INSERT.execute(this.db2, data);
        log.info("Dataset Output Complete");
    }
    if (this.outFile != null) {
        FlatDtdDataSet.write(data, this.outFile);
    }
}

From source file:org.jumpmind.db.model.Column.java

/**
 * Tries to parse the default value of the column and returns it as an
 * object of the corresponding java type. If the value could not be parsed,
 * then the original definition is returned.
 * //w  w  w.  j  av a 2 s .  co  m
 * @return The parsed default value
 */
public Object getParsedDefaultValue() {
    if ((defaultValue != null) && (defaultValue.length() > 0)) {
        try {
            switch (mappedTypeCode) {
            case Types.TINYINT:
            case Types.SMALLINT:
                return new Short(defaultValue);
            case Types.INTEGER:
                try {
                    return new Integer(defaultValue);
                } catch (NumberFormatException e) {
                    return new Long(defaultValue);
                }
            case Types.BIGINT:
                return new Long(defaultValue);
            case Types.DECIMAL:
            case Types.NUMERIC:
                return new BigDecimal(defaultValue);
            case Types.REAL:
                return new Float(defaultValue);
            case Types.DOUBLE:
            case Types.FLOAT:
                return new Double(defaultValue);
            case Types.DATE:
                return Date.valueOf(defaultValue);
            case Types.TIME:
                return Time.valueOf(defaultValue);
            case Types.TIMESTAMP:
                return Timestamp.valueOf(defaultValue);
            case Types.BIT:
                return FormatUtils.toBoolean(defaultValue);
            default:
                if (PlatformUtils.supportsJava14JdbcTypes()
                        && (mappedTypeCode == PlatformUtils.determineBooleanTypeCode())) {
                    return FormatUtils.toBoolean(defaultValue);
                }
                break;
            }
        } catch (NumberFormatException ex) {
            return null;
        } catch (IllegalArgumentException ex) {
            return null;
        }
    }
    return defaultValue;
}

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

@Override
public void setToPreparedStatement(PreparedStatement ps, int index, Serializable value, Column column)
        throws SQLException {
    switch (column.getJdbcType()) {
    case Types.VARCHAR:
    case Types.CLOB:
        setToPreparedStatementString(ps, index, value, column);
        return;//  w  w  w  . j  a v a  2  s  .com
    case Types.BIT:
        ps.setBoolean(index, ((Boolean) value).booleanValue());
        return;
    case Types.TINYINT:
    case Types.SMALLINT:
        ps.setInt(index, ((Long) value).intValue());
        return;
    case Types.INTEGER:
    case Types.BIGINT:
        ps.setLong(index, ((Number) value).longValue());
        return;
    case Types.DOUBLE:
        ps.setDouble(index, ((Double) value).doubleValue());
        return;
    case Types.TIMESTAMP:
        setToPreparedStatementTimestamp(ps, index, value, column);
        return;
    case Types.OTHER:
        ColumnType type = column.getType();
        if (type.isId()) {
            setId(ps, index, value);
            return;
        } else if (type == ColumnType.FTSTORED) {
            ps.setString(index, (String) value);
            return;
        }
        throw new SQLException("Unhandled type: " + column.getType());
    default:
        throw new SQLException("Unhandled JDBC type: " + column.getJdbcType());
    }
}

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

@Override
public void setToPreparedStatement(PreparedStatement ps, int index, Serializable value, Column column)
        throws SQLException {
    switch (column.getJdbcType()) {
    case Types.VARCHAR:
    case Types.CLOB:
        setToPreparedStatementString(ps, index, value, column);
        return;//  ww w .java2s  .  c  om
    case Types.BIT:
        ps.setBoolean(index, ((Boolean) value).booleanValue());
        return;
    case Types.SMALLINT:
        ps.setInt(index, ((Long) value).intValue());
        return;
    case Types.INTEGER:
    case Types.BIGINT:
        ps.setLong(index, ((Number) value).longValue());
        return;
    case Types.DOUBLE:
        ps.setDouble(index, ((Double) value).doubleValue());
        return;
    case Types.TIMESTAMP:
        ps.setTimestamp(index, getTimestampFromCalendar((Calendar) value));
        return;
    case Types.ARRAY:
        int jdbcBaseType = column.getJdbcBaseType();
        String jdbcBaseTypeName = column.getSqlBaseTypeString();
        if (jdbcBaseType == Types.TIMESTAMP) {
            value = getTimestampFromCalendar((Serializable[]) value);
        }
        Array array = ps.getConnection().createArrayOf(jdbcBaseTypeName, (Object[]) value);
        ps.setArray(index, array);
        return;
    case Types.OTHER:
        ColumnType type = column.getType();
        if (type.isId()) {
            setId(ps, index, value);
            return;
        } else if (type == ColumnType.FTSTORED) {
            ps.setString(index, (String) value);
            return;
        }
        throw new SQLException("Unhandled type: " + column.getType());
    default:
        throw new SQLException("Unhandled JDBC type: " + column.getJdbcType());
    }
}

From source file:org.executequery.gui.importexport.AbstractImportExportWorker.java

/**
 * Sets the specified value in the specified position for the
 * specified java.sql.Type within the prepared statement.
 *
 * @param value - the value//  www .  j  ava  2s .  co m
 * @param index - the position within the statement
 * @param sqlType - the SQL type
 * @param trim - whether to trim the whitespace from the value
 * @param df - the DataFormat object for date values
 */
protected void setValue(String value, int index, int sqlType, boolean trim, DateFormat df) throws Exception {

    if (value == null) {

        prepStmnt.setNull(index, sqlType);

    } else {

        switch (sqlType) {

        case Types.TINYINT:
            byte _byte = Byte.valueOf(value).byteValue();
            prepStmnt.setShort(index, _byte);
            break;

        case Types.BIGINT:
            long _long = Long.valueOf(value).longValue();
            prepStmnt.setLong(index, _long);
            break;

        case Types.SMALLINT:
            short _short = Short.valueOf(value).shortValue();
            prepStmnt.setShort(index, _short);
            break;

        case Types.LONGVARCHAR:
        case Types.CHAR:
        case Types.VARCHAR:
            if (trim) {
                value = value.trim();
            }
            prepStmnt.setString(index, value);
            break;

        case Types.BIT:
        case Types.BOOLEAN:

            String booleanValue = value;
            if ("t".equalsIgnoreCase(value)) {

                booleanValue = "true";

            } else if ("f".equalsIgnoreCase(value)) {

                booleanValue = "false";
            }

            boolean _boolean = Boolean.valueOf(booleanValue).booleanValue();
            prepStmnt.setBoolean(index, _boolean);
            break;

        case Types.NUMERIC:
        case Types.DECIMAL:
            prepStmnt.setBigDecimal(index, new BigDecimal(value));
            break;

        case Types.REAL:
            float _float = Float.valueOf(value).floatValue();
            prepStmnt.setFloat(index, _float);
            break;

        case Types.FLOAT:
        case Types.DOUBLE:
            prepStmnt.setDouble(index, Double.parseDouble(value));
            break;

        case Types.INTEGER:
            prepStmnt.setInt(index, Integer.parseInt(value));
            break;

        case Types.DATE:
        case Types.TIME:
        case Types.TIMESTAMP:
            // if the date format is null, insert as a char value
            if (df != null) {
                java.util.Date j_datetime = df.parse(value);
                prepStmnt.setDate(index, new java.sql.Date(j_datetime.getTime()));
            } else {
                try {
                    prepStmnt.setObject(index, value, sqlType);
                    /*
                    if (sqlType == Types.TIMESTAMP) {
                        prepStmnt.setTimestamp(index,
                                java.sql.Timestamp.valueOf(value));
                    }
                    else if (sqlType == Types.TIME) {
                        prepStmnt.setTime(index,
                                java.sql.Time.valueOf(value));
                    }
                    else {
                        prepStmnt.setDate(index,
                                java.sql.Date.valueOf(value));
                    }
                     */
                }
                // want a more useful message here than what will likely
                // be returned due to internal driver code on formatting
                // a SQL date value from string
                // (ie. could be parsing error, number format etc...)
                catch (Exception e) {
                    throw new IllegalArgumentException("[ " + MiscUtils.getExceptionName(e) + " ] "
                            + getBundle().getString("AbstractImportExportWorker.dateConversionError"));
                }

            }
            break;

        case Types.LONGVARBINARY:
        case Types.BINARY:
        case Types.BLOB:
        case Types.CLOB:
            prepStmnt.setBytes(index, Base64.decode(value));
            break;

        default:
            prepStmnt.setObject(index, value);
            break;
        }
    }
}

From source file:org.apache.oozie.command.SchemaCheckXCommand.java

private String getSQLTypeFromInt(int t) {
    switch (t) {/*from ww  w.j  a  v  a  2s.  co  m*/
    case Types.BIT:
        return "BIT";
    case Types.TINYINT:
        return "TINYINT";
    case Types.SMALLINT:
        return "SMALLINT";
    case Types.INTEGER:
        return "INTEGER";
    case Types.BIGINT:
        return "BIGINT";
    case Types.FLOAT:
        return "FLOAT";
    case Types.REAL:
        return "REAL";
    case Types.DOUBLE:
        return "DOUBLE";
    case Types.NUMERIC:
        return "NUMERIC";
    case Types.DECIMAL:
        return "DECIMAL";
    case Types.CHAR:
        return "CHAR";
    case Types.VARCHAR:
        return "VARCHAR";
    case Types.LONGVARCHAR:
        return "LONGVARCHAR";
    case Types.DATE:
        return "DATE";
    case Types.TIME:
        return "TIME";
    case Types.TIMESTAMP:
        return "TIMESTAMP";
    case Types.BINARY:
        return "BINARY";
    case Types.VARBINARY:
        return "VARBINARY";
    case Types.LONGVARBINARY:
        return "LONGVARBINARY";
    case Types.NULL:
        return "NULL";
    case Types.OTHER:
        return "OTHER";
    case Types.JAVA_OBJECT:
        return "JAVA_OBJECT";
    case Types.DISTINCT:
        return "DISTINCT";
    case Types.STRUCT:
        return "STRUCT";
    case Types.ARRAY:
        return "ARRAY";
    case Types.BLOB:
        return "BLOB";
    case Types.CLOB:
        return "CLOB";
    case Types.REF:
        return "REF";
    case Types.DATALINK:
        return "DATALINK";
    case Types.BOOLEAN:
        return "BOOLEAN";
    case Types.ROWID:
        return "ROWID";
    case Types.NCHAR:
        return "NCHAR";
    case Types.NVARCHAR:
        return "NVARCHAR";
    case Types.LONGNVARCHAR:
        return "LONGNVARCHAR";
    case Types.NCLOB:
        return "NCLOB";
    case Types.SQLXML:
        return "SQLXML";
    default:
        return "unknown";
    }
}

From source file:org.waarp.common.database.data.AbstractDbData.java

/**
 * Get one value into DbValue from ResultSet
 * /*from ww  w . j a va  2  s.co m*/
 * @param rs
 * @param value
 * @throws WaarpDatabaseSqlException
 */
static public void getTrueValue(ResultSet rs, DbValue value) throws WaarpDatabaseSqlException {
    try {
        switch (value.type) {
        case Types.VARCHAR:
            value.value = rs.getString(value.column);
            break;
        case Types.LONGVARCHAR:
            value.value = rs.getString(value.column);
            break;
        case Types.BIT:
            value.value = rs.getBoolean(value.column);
            break;
        case Types.TINYINT:
            value.value = rs.getByte(value.column);
            break;
        case Types.SMALLINT:
            value.value = rs.getShort(value.column);
            break;
        case Types.INTEGER:
            value.value = rs.getInt(value.column);
            break;
        case Types.BIGINT:
            value.value = rs.getLong(value.column);
            break;
        case Types.REAL:
            value.value = rs.getFloat(value.column);
            break;
        case Types.DOUBLE:
            value.value = rs.getDouble(value.column);
            break;
        case Types.VARBINARY:
            value.value = rs.getBytes(value.column);
            break;
        case Types.DATE:
            value.value = rs.getDate(value.column);
            break;
        case Types.TIMESTAMP:
            value.value = rs.getTimestamp(value.column);
            break;
        case Types.CLOB:
            value.value = rs.getClob(value.column).getCharacterStream();
            break;
        case Types.BLOB:
            value.value = rs.getBlob(value.column).getBinaryStream();
            break;
        default:
            throw new WaarpDatabaseSqlException("Type not supported: " + value.type + " for " + value.column);
        }
    } catch (SQLException e) {
        DbSession.error(e);
        throw new WaarpDatabaseSqlException("Getting values in error: " + value.type + " for " + value.column,
                e);
    }
}

From source file:com.squid.core.domain.operators.ExtendedType.java

public static IDomain computeDomain(int data_type, int size, int scale) {
    switch (data_type) {
    case Types.BOOLEAN:
    case Types.BIT:// on PG systems, this is how a boolean is actually represented by the driver
        return IDomain.BOOLEAN;
    case Types.TINYINT:
    case Types.BIGINT:
    case Types.INTEGER:
    case Types.SMALLINT:
        return IDomain.NUMERIC;
    ///////////////////////////
    case Types.REAL:
    case Types.DOUBLE:
    case Types.FLOAT:
        return IDomain.CONTINUOUS;
    case Types.NUMERIC:
    case Types.DECIMAL:
        return scale > 0 || size == 0 ? IDomain.CONTINUOUS : IDomain.NUMERIC;
    case Types.CHAR:
    case Types.NCHAR:
    case Types.VARCHAR:
    case Types.NVARCHAR:
    case Types.LONGVARCHAR:
    case Types.CLOB:
        return IDomain.STRING;
    ///////////////////////////
    case Types.TIME:
        return IDomain.TIME;
    case Types.DATE:
        return IDomain.DATE;
    case Types.TIMESTAMP:
        return IDomain.TIMESTAMP;
    ///////////////////////////
    default:/*from   ww w  .  j a  va 2  s.co  m*/
        return IDomain.UNKNOWN;
    }
}

From source file:org.sakaiproject.webservices.SakaiReport.java

private String getColumnValue(ResultSet rs, int colType, int colIndex) throws SQLException, IOException {
    String value = "";
    switch (colType) {
    case Types.BIT:
    case Types.JAVA_OBJECT:
        value = handleObject(rs.getObject(colIndex));
        break;//from  w  ww  .  j a  v a 2  s. com
    case Types.BOOLEAN:
        boolean b = rs.getBoolean(colIndex);
        value = Boolean.valueOf(b).toString();
        break;
    case NCLOB: // todo : use rs.getNClob
    case Types.CLOB:
        Clob c = rs.getClob(colIndex);
        if (c != null) {
            value = read(c);
        }
        break;
    case Types.BIGINT:
        value = handleLong(rs, colIndex);
        break;
    case Types.DECIMAL:
    case Types.DOUBLE:
    case Types.FLOAT:
    case Types.REAL:
    case Types.NUMERIC:
        value = handleBigDecimal(rs.getBigDecimal(colIndex));
        break;
    case Types.INTEGER:
    case Types.TINYINT:
    case Types.SMALLINT:
        value = handleInteger(rs, colIndex);
        break;
    case Types.DATE:
        value = handleDate(rs, colIndex);
        break;
    case Types.TIME:
        value = handleTime(rs.getTime(colIndex));
        break;
    case Types.TIMESTAMP:
        value = handleTimestamp(rs.getTimestamp(colIndex));
        break;
    case NVARCHAR: // todo : use rs.getNString
    case NCHAR: // todo : use rs.getNString
    case LONGNVARCHAR: // todo : use rs.getNString
    case Types.LONGVARCHAR:
    case Types.VARCHAR:
    case Types.CHAR:
        value = rs.getString(colIndex);
        break;
    case Types.VARBINARY:
    case Types.BINARY:
        value = handleRaw(rs.getBytes(colIndex));
        break;
    default:
        value = "";
    }

    if (value == null) {
        value = "";
    }

    return value;

}