Example usage for java.sql Types BOOLEAN

List of usage examples for java.sql Types BOOLEAN

Introduction

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

Prototype

int BOOLEAN

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

Click Source Link

Document

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

Usage

From source file:org.apache.syncope.core.util.ContentExporter.java

private String getValues(final ResultSet rs, final String columnName, final Integer columnType)
        throws SQLException {

    String res = null;// w w  w . ja v a  2  s . c  o m

    try {
        switch (columnType) {
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
            final InputStream is = rs.getBinaryStream(columnName);
            if (is != null) {
                res = new String(Hex.encode(IOUtils.toByteArray(is)));
            }
            break;

        case Types.BLOB:
            final Blob blob = rs.getBlob(columnName);
            if (blob != null) {
                res = new String(Hex.encode(IOUtils.toByteArray(blob.getBinaryStream())));
            }
            break;

        case Types.BIT:
        case Types.BOOLEAN:
            if (rs.getBoolean(columnName)) {
                res = "1";
            } else {
                res = "0";
            }
            break;

        case Types.DATE:
        case Types.TIME:
        case Types.TIMESTAMP:
            final Timestamp timestamp = rs.getTimestamp(columnName);
            if (timestamp != null) {
                res = DataFormat.format(new Date(timestamp.getTime()));
            }
            break;

        default:
            res = rs.getString(columnName);
        }
    } catch (IOException e) {
        LOG.error("Error retrieving hexadecimal string", e);
    }

    return res;
}

From source file:org.dashbuilder.dataprovider.backend.sql.JDBCUtils.java

public static ColumnType calculateType(int sqlDataType) {
    switch (sqlDataType) {

    // Category-like columns.
    case Types.CHAR:
    case Types.VARCHAR:
    case Types.NCHAR:
    case Types.NVARCHAR:
    case Types.BIT:
    case Types.BOOLEAN: {
        return ColumnType.LABEL;
    }/*from  ww  w.  j a  v a 2 s .c  om*/

    // Text-like columns.
    case Types.LONGVARCHAR:
    case Types.LONGNVARCHAR: {
        return ColumnType.TEXT;
    }

    // Number-like columns.
    case Types.TINYINT:
    case Types.BIGINT:
    case Types.INTEGER:
    case Types.DECIMAL:
    case Types.DOUBLE:
    case Types.FLOAT:
    case Types.NUMERIC:
    case Types.REAL:
    case Types.SMALLINT: {
        return ColumnType.NUMBER;
    }

    // Date-like columns.
    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP: {
        return ColumnType.DATE;
    }

    /*case Types.BINARY:
    case Types.VARBINARY:
    case Types.LONGVARBINARY:
    case Types.NULL:
    case Types.OTHER:
    case Types.JAVA_OBJECT:
    case Types.DISTINCT:
    case Types.STRUCT:
    case Types.ARRAY:
    case Types.BLOB:
    case Types.CLOB:
    case Types.REF:
    case Types.ROWID:
    case Types.SQLXML:
    case Types.DATALINK:*/

    // Unsupported (see above) types are treated as a text values.
    default: {
        return ColumnType.TEXT;
    }
    }
}

From source file:net.riezebos.thoth.configuration.persistence.dbs.DDLExecuter.java

private void initDialect(DatabaseIdiom idiom) {
    databaseIdiom = idiom;//w w w.  j av a 2 s.com
    try {
        addTranslation("bigint", idiom.getTypeName(Types.BIGINT));
        addTranslation("binary", idiom.getTypeName(Types.BINARY));
        addTranslation("bit", idiom.getTypeName(Types.BIT));
        addTranslation("blob", idiom.getTypeName(Types.BLOB));
        addTranslation("boolean", idiom.getTypeName(Types.BOOLEAN));
        addTranslation("char", idiom.getTypeName(Types.CHAR));
        addTranslation("clob", idiom.getTypeName(Types.CLOB));
        addTranslation("date", idiom.getTypeName(Types.DATE));
        addTranslation("decimal", idiom.getTypeName(Types.DECIMAL));
        addTranslation("double", idiom.getTypeName(Types.DOUBLE));
        addTranslation("float", idiom.getTypeName(Types.FLOAT));
        addTranslation("integer", idiom.getTypeName(Types.INTEGER));
        addTranslation("longnvarchar", idiom.getTypeName(Types.LONGNVARCHAR));
        addTranslation("longvarbinary", idiom.getTypeName(Types.LONGVARBINARY));
        addTranslation("longvarchar", idiom.getTypeName(Types.LONGVARCHAR));
        addTranslation("nchar", idiom.getTypeName(Types.NCHAR));
        addTranslation("nclob", idiom.getTypeName(Types.NCLOB));
        addTranslation("numeric", idiom.getTypeName(Types.NUMERIC));
        addTranslation("nvarchar", idiom.getTypeName(Types.NVARCHAR));
        addTranslation("real", idiom.getTypeName(Types.REAL));
        addTranslation("smallint", idiom.getTypeName(Types.SMALLINT));
        addTranslation("time", idiom.getTypeName(Types.TIME));
        addTranslation("timestamp", idiom.getTypeName(Types.TIMESTAMP));
        addTranslation("tinyint", idiom.getTypeName(Types.TINYINT));
        addTranslation("varbinary", idiom.getTypeName(Types.VARBINARY));

        databaseIdiom.initDialect(translations, workarounds);
        // Ignore autogenerated ID's
        addWorkaround("generated always as identity", "");
    } catch (Exception e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:CSVWriter.java

private static String getColumnValue(ResultSet rs, int colType, int colIndex)
    throws SQLException, IOException {

  String value = "";
      /*from w  w w. j  a v  a 2 s . c  om*/
switch (colType)
{
  case Types.BIT:
    Object bit = rs.getObject(colIndex);
    if (bit != null) {
      value = String.valueOf(bit);
    }
  break;
  case Types.BOOLEAN:
    boolean b = rs.getBoolean(colIndex);
    if (!rs.wasNull()) {
      value = Boolean.valueOf(b).toString();
    }
  break;
  case Types.CLOB:
    Clob c = rs.getClob(colIndex);
    if (c != null) {
      value = read(c);
    }
  break;
  case Types.BIGINT:
  case Types.DECIMAL:
  case Types.DOUBLE:
  case Types.FLOAT:
  case Types.REAL:
  case Types.NUMERIC:
    BigDecimal bd = rs.getBigDecimal(colIndex);
    if (bd != null) {
      value = "" + bd.doubleValue();
    }
  break;
  case Types.INTEGER:
  case Types.TINYINT:
  case Types.SMALLINT:
    int intValue = rs.getInt(colIndex);
    if (!rs.wasNull()) {
      value = "" + intValue;
    }
  break;
  case Types.JAVA_OBJECT:
    Object obj = rs.getObject(colIndex);
    if (obj != null) {
      value = String.valueOf(obj);
    }
  break;
  case Types.DATE:
    java.sql.Date date = rs.getDate(colIndex);
    if (date != null) {
      value = DATE_FORMATTER.format(date);;
    }
  break;
  case Types.TIME:
    Time t = rs.getTime(colIndex);
    if (t != null) {
      value = t.toString();
    }
  break;
  case Types.TIMESTAMP:
    Timestamp tstamp = rs.getTimestamp(colIndex);
    if (tstamp != null) {
      value = TIMESTAMP_FORMATTER.format(tstamp);
    }
  break;
  case Types.LONGVARCHAR:
  case Types.VARCHAR:
  case Types.CHAR:
    value = rs.getString(colIndex);
  break;
  default:
    value = "";
}

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

From source file:at.bestsolution.persistence.java.Util.java

public static void setValue(PreparedStatement pstmt, int parameterIndex, TypedValue value) throws SQLException {
    if (value.value == null) {
        int sqlType;
        switch (value.type) {
        case INT:
            sqlType = Types.INTEGER;
            break;
        case DOUBLE:
            sqlType = Types.DECIMAL;
            break;
        case FLOAT:
            sqlType = Types.FLOAT;
            break;
        case BOOLEAN:
            sqlType = Types.BOOLEAN;
            break;
        case LONG:
            sqlType = Types.BIGINT;
            break;
        case STRING:
            sqlType = Types.VARCHAR;
            break;
        case BLOB:
            sqlType = Types.BLOB;
            break;
        case CLOB:
            sqlType = Types.CLOB;
            break;
        case TIMESTAMP:
            sqlType = Types.TIMESTAMP;
            break;
        default://from   w  w  w. j ava2  s.  co m
            sqlType = Types.OTHER;
            break;
        }
        pstmt.setNull(parameterIndex, sqlType);
    } else {
        switch (value.type) {
        case INT:
            pstmt.setInt(parameterIndex, ((Number) value.value).intValue());
            break;
        case DOUBLE:
            pstmt.setDouble(parameterIndex, ((Number) value.value).doubleValue());
            break;
        case FLOAT:
            pstmt.setDouble(parameterIndex, ((Number) value.value).doubleValue());
            break;
        case BOOLEAN:
            pstmt.setBoolean(parameterIndex, Boolean.TRUE.equals(value.value));
            break;
        case LONG:
            pstmt.setLong(parameterIndex, ((Number) value.value).longValue());
            break;
        case STRING:
            pstmt.setString(parameterIndex, (String) value.value);
            break;
        case TIMESTAMP:
            if (value.value instanceof Timestamp) {
                pstmt.setTimestamp(parameterIndex, (Timestamp) value.value);
            } else {
                pstmt.setTimestamp(parameterIndex, new Timestamp(((Date) value.value).getTime()));
            }
            break;
        case UNKNOWN:
            pstmt.setObject(parameterIndex, value.value);
            break;
        default:
            throw new IllegalStateException("Unknown type");
        }
    }
}

From source file:org.easyrec.store.dao.core.impl.ProfileDAOMysqlImpl.java

public String getProfile(Integer tenantId, Integer itemId, Integer itemTypeId, Boolean active) {
    if (tenantId == null) {
        throw new IllegalArgumentException("tenantId must not be 'null'!");
    }//w ww.j  a v  a  2s  .com
    if (itemId == null) {
        throw new IllegalArgumentException("itemId must not be 'null'!");
    }
    if (itemTypeId == null) {
        throw new IllegalArgumentException("itemTypeId must not be 'null'");
    }

    String itemType = itemTypeDAO.getTypeById(tenantId, itemTypeId);
    String mappedItemId = idMappingDAO.lookup(itemId);
    if (mappedItemId == null)
        throw new IllegalArgumentException("itemId has no string equivalent");

    Object[] args;
    int[] argTypes;

    if (active == null) {
        args = new Object[] { tenantId, mappedItemId, itemType };
        argTypes = new int[] { Types.INTEGER, Types.VARCHAR, Types.VARCHAR };

        return getJdbcTemplate().queryForObject(GET_PROFILE_QUERY, args, argTypes, String.class);
    } else {
        args = new Object[] { tenantId, mappedItemId, itemType, active };
        argTypes = new int[] { Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.BOOLEAN };

        return getJdbcTemplate().queryForObject(GET_ACTIVE_PROFILE_QUERY, args, argTypes, String.class);
    }
}

From source file:org.dashbuilder.dataprovider.sql.JDBCUtils.java

public static ColumnType calculateType(int sqlDataType) {
    switch (sqlDataType) {

    // Category-like columns.
    case Types.CHAR:
    case Types.VARCHAR:
    case Types.NCHAR:
    case Types.NVARCHAR:
    case Types.BIT:
    case Types.BOOLEAN: {
        return ColumnType.LABEL;
    }//from  w w w  .java  2s.c  o m

    // Text-like columns.
    case Types.LONGVARCHAR:
    case Types.LONGNVARCHAR: {
        return ColumnType.TEXT;
    }

    // Number-like columns.
    case Types.TINYINT:
    case Types.BIGINT:
    case Types.INTEGER:
    case Types.DECIMAL:
    case Types.DOUBLE:
    case Types.FLOAT:
    case Types.NUMERIC:
    case Types.REAL:
    case Types.SMALLINT: {
        return ColumnType.NUMBER;
    }

    // Date-like columns.
    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP: {
        return ColumnType.DATE;
    }

    // Unsupported
    default: {
        return null;
    }
    }
}

From source file:uk.org.rbc1b.roms.controller.report.ReportsController.java

private ReportResults extractResults(String sql) throws SQLException {
    Connection con = DataSourceUtils.getConnection(dataSource);
    Statement s = con.createStatement();

    ResultSet rs = s.executeQuery(sql);

    ReportResults reportResults = new ReportResults();

    ResultSetMetaData rsmd = rs.getMetaData();
    int columnCount = rsmd.getColumnCount();

    List<Integer> columnTypeIds = new ArrayList<Integer>();
    for (int i = 0; i < columnCount; i++) {
        columnTypeIds.add(rsmd.getColumnType(i + 1));
    }// w  w  w.  jav  a  2s. com

    reportResults.columnNames = new ArrayList<String>();
    for (int i = 0; i < columnCount; i++) {
        reportResults.columnNames.add(rsmd.getColumnLabel(i + 1));
    }

    reportResults.resultRows = new ArrayList<List<String>>();
    while (rs.next()) {
        List<String> resultRow = new ArrayList<String>();

        for (int i = 0; i < columnCount; i++) {
            Integer columnTypeId = columnTypeIds.get(i);
            if (columnTypeId.intValue() == Types.BOOLEAN || columnTypeId.intValue() == Types.BIT) {
                resultRow.add(Boolean.valueOf(rs.getBoolean(i + 1)).toString());
            } else {
                resultRow.add(rs.getString(i + 1));
            }
        }

        reportResults.resultRows.add(resultRow);
    }

    return reportResults;
}

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;/*from  w  w  w  .  j a va 2 s. c o m*/
    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:org.cloudgraph.rdb.service.RDBDataConverter.java

private int convertToSqlType(Property property, Object value) {
    int result;/* w  w w .jav  a  2s  . co m*/
    if (!property.getType().isDataType())
        throw new IllegalArgumentException("expected data type property, not " + property.toString());
    DataType dataType = DataType.valueOf(property.getType().getName());
    switch (dataType) {
    case String:
    case URI:
    case Month:
    case MonthDay:
    case Day:
    case Time:
    case Year:
    case YearMonth:
    case YearMonthDay:
    case Duration:
    case Strings:
        result = java.sql.Types.VARCHAR;
        break;
    case Date:
        // Plasma SDO allows more precision than just month/day/year
        // in an SDO date datatype, and using java.sql.Date will
        // truncate
        // here so use java.sql.Timestamp.
        result = java.sql.Types.TIMESTAMP;
        break;
    case DateTime:
        result = java.sql.Types.TIMESTAMP;
        // FIXME: so what SDO datatype maps to a SQL timestamp??
        break;
    case Decimal:
        result = java.sql.Types.DECIMAL;
        break;
    case Bytes:
        // FIXME: how do we know whether a Blob here
        result = java.sql.Types.VARBINARY;
        break;
    case Byte:
        result = java.sql.Types.VARBINARY;
        break;
    case Boolean:
        result = java.sql.Types.BOOLEAN;
        break;
    case Character:
        result = java.sql.Types.CHAR;
        break;
    case Double:
        result = java.sql.Types.DOUBLE;
        break;
    case Float:
        result = java.sql.Types.FLOAT;
        break;
    case Int:
        result = java.sql.Types.INTEGER;
        break;
    case Integer:
        result = java.sql.Types.BIGINT;
        break;
    case Long:
        result = java.sql.Types.INTEGER; // FIXME: no JDBC long??
        break;
    case Short:
        result = java.sql.Types.SMALLINT;
        break;
    case Object:
    default:
        result = java.sql.Types.VARCHAR;
        break;
    }
    return result;
}