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:com.nabla.wapp.server.json.SqlColumn.java

public SqlColumn(String label, int type, int length) {
    this.label = label;
    this.type = (type == Types.TINYINT) ? (length == 1 ? Types.BOOLEAN : type) : type;
    if (log.isDebugEnabled()) {
        String s;//from   w  ww  .j  a  v  a 2 s  . c  om
        switch (this.type) {
        case Types.BIGINT:
        case Types.INTEGER:
        case Types.SMALLINT:
        case Types.TINYINT:
            s = "INTEGER";
            break;
        case Types.BOOLEAN:
        case Types.BIT:
            s = "BOOLEAN";
            break;
        case Types.DATE:
            s = "DATE";
            break;
        case Types.TIMESTAMP:
            s = "TIMESTAMP";
            break;
        case Types.DOUBLE:
            s = "DOUBLE";
            break;
        case Types.FLOAT:
            s = "FLOAT";
            break;
        case Types.NULL:
            s = "NULL";
            break;
        default:
            s = "STRING";
            break;
        }
        log.debug("column '" + this.label + "' " + s);
    }
}

From source file:com.streamsets.pipeline.stage.it.AllNullTypesIT.java

@Parameterized.Parameters(name = "type({0})")
public static Collection<Object[]> data() throws Exception {
    return Arrays.asList(new Object[][] { { Field.create(Field.Type.BOOLEAN, null), true, Types.BOOLEAN },
            { Field.create(Field.Type.CHAR, null), true, Types.VARCHAR },
            { Field.create(Field.Type.BYTE, null), false, 0 },
            { Field.create(Field.Type.SHORT, null), true, Types.INTEGER },
            { Field.create(Field.Type.INTEGER, null), true, Types.INTEGER },
            { Field.create(Field.Type.LONG, null), true, Types.BIGINT },
            { Field.create(Field.Type.FLOAT, null), true, Types.FLOAT },
            { Field.create(Field.Type.DOUBLE, null), true, Types.DOUBLE },
            { Field.create(Field.Type.DATE, null), true, Types.DATE },
            { Field.create(Field.Type.DATETIME, null), true, Types.VARCHAR },
            { Field.create(Field.Type.TIME, null), true, Types.VARCHAR },
            { Field.create(Field.Type.DECIMAL, null), true, Types.DECIMAL },
            { Field.create(Field.Type.STRING, null), true, Types.VARCHAR },
            { Field.create(Field.Type.BYTE_ARRAY, null), true, Types.BINARY },
            { Field.create(Field.Type.MAP, null), false, 0 }, { Field.create(Field.Type.LIST, null), false, 0 },
            { Field.create(Field.Type.LIST_MAP, null), false, 0 }, });
}

From source file:com.espertech.esper.util.TestSQLTypeMapUtil.java

public void testMapping() {
    Map<Integer, Class> testData = new HashMap<Integer, Class>();
    testData.put(Types.CHAR, String.class);
    testData.put(Types.VARCHAR, String.class);
    testData.put(Types.LONGVARCHAR, String.class);
    testData.put(Types.NUMERIC, BigDecimal.class);
    testData.put(Types.DECIMAL, BigDecimal.class);
    testData.put(Types.BIT, Boolean.class);
    testData.put(Types.BOOLEAN, Boolean.class);
    testData.put(Types.TINYINT, Byte.class);
    testData.put(Types.SMALLINT, Short.class);
    testData.put(Types.INTEGER, Integer.class);
    testData.put(Types.BIGINT, Long.class);
    testData.put(Types.REAL, Float.class);
    testData.put(Types.FLOAT, Double.class);
    testData.put(Types.DOUBLE, Double.class);
    testData.put(Types.BINARY, byte[].class);
    testData.put(Types.VARBINARY, byte[].class);
    testData.put(Types.LONGVARBINARY, byte[].class);
    testData.put(Types.DATE, java.sql.Date.class);
    testData.put(Types.TIMESTAMP, java.sql.Timestamp.class);
    testData.put(Types.TIME, java.sql.Time.class);
    testData.put(Types.CLOB, java.sql.Clob.class);
    testData.put(Types.BLOB, java.sql.Blob.class);
    testData.put(Types.ARRAY, java.sql.Array.class);
    testData.put(Types.STRUCT, java.sql.Struct.class);
    testData.put(Types.REF, java.sql.Ref.class);
    testData.put(Types.DATALINK, java.net.URL.class);

    for (int type : testData.keySet()) {
        Class result = SQLTypeMapUtil.sqlTypeToClass(type, null);
        log.debug(".testMapping Mapping " + type + " to " + result.getSimpleName());
        assertEquals(testData.get(type), result);
    }//from   www.j  a va2s .c om

    assertEquals(String.class, SQLTypeMapUtil.sqlTypeToClass(Types.JAVA_OBJECT, "java.lang.String"));
    assertEquals(String.class, SQLTypeMapUtil.sqlTypeToClass(Types.DISTINCT, "java.lang.String"));
}

From source file:org.apache.ddlutils.io.converters.NumberConverter.java

/**
 * {@inheritDoc}/*from w w w  .  ja v  a 2 s .  com*/
 */
public Object convertFromString(String textRep, int sqlTypeCode) throws ConversionException {
    if (textRep == null) {
        return null;
    } else {
        Class targetClass = null;

        switch (sqlTypeCode) {
        case Types.BIGINT:
            targetClass = Long.class;
            break;
        case Types.BIT:
        case Types.BOOLEAN:
            targetClass = Boolean.class;
            break;
        case Types.DECIMAL:
        case Types.NUMERIC:
            targetClass = BigDecimal.class;
            break;
        case Types.DOUBLE:
        case Types.FLOAT:
            targetClass = Double.class;
            break;
        case Types.INTEGER:
            targetClass = Integer.class;
            break;
        case Types.REAL:
            targetClass = Float.class;
            break;
        case Types.SMALLINT:
        case Types.TINYINT:
            targetClass = Short.class;
            break;
        }
        return targetClass == null ? textRep : ConvertUtils.convert(textRep, targetClass);
    }
}

From source file:at.alladin.rmbt.db.fields.BooleanField.java

@Override
public void getField(final PreparedStatement ps, final int idx) throws SQLException {
    if (value == null)
        ps.setNull(idx, Types.BOOLEAN);
    else/*  w  w w.  ja  va  2 s .com*/
        ps.setBoolean(idx, value);
}

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

/**
 * Converts the given default value from the specified original to the target
 * jdbc type./*from w  ww.j  a va2s  .c  o m*/
 * 
 * @param defaultValue     The default value
 * @param originalTypeCode The original type code
 * @param targetTypeCode   The target type code
 * @return The converted default value 
 */
public String convert(String defaultValue, int originalTypeCode, int targetTypeCode) {
    String result = defaultValue;

    if (defaultValue != null) {
        switch (originalTypeCode) {
        case Types.BIT:
        case Types.BOOLEAN:
            result = convertBoolean(defaultValue, targetTypeCode).toString();
            break;
        case Types.DATE:
            if (targetTypeCode == Types.TIMESTAMP) {
                try {
                    Date date = Date.valueOf(result);

                    return new Timestamp(date.getTime()).toString();
                } catch (IllegalArgumentException ex) {
                }
            }
            break;
        case Types.TIME:
            if (targetTypeCode == Types.TIMESTAMP) {
                try {
                    Time time = Time.valueOf(result);

                    return new Timestamp(time.getTime()).toString();
                } catch (IllegalArgumentException ex) {
                }
            }
            break;
        }
    }
    return result;
}

From source file:com.streamsets.pipeline.stage.it.AllSdcTypesIT.java

@Parameterized.Parameters(name = "type({0})")
public static Collection<Object[]> data() throws Exception {
    return Arrays.asList(new Object[][] { { Field.create(Field.Type.BOOLEAN, true), true, Types.BOOLEAN, true },
            { Field.create(Field.Type.CHAR, 'A'), true, Types.VARCHAR, "A" },
            { Field.create(Field.Type.BYTE, (byte) 0x00), false, 0, null },
            { Field.create(Field.Type.SHORT, 10), true, Types.INTEGER, 10 },
            { Field.create(Field.Type.INTEGER, 10), true, Types.INTEGER, 10 },
            { Field.create(Field.Type.LONG, 10), true, Types.BIGINT, 10L },
            { Field.create(Field.Type.FLOAT, 1.5), true, Types.FLOAT, 1.5 },
            { Field.create(Field.Type.DOUBLE, 1.5), true, Types.DOUBLE, 1.5 },
            { Field.create(Field.Type.DATE, new Date(116, 5, 13)), true, Types.DATE, new Date(116, 5, 13) },
            { Field.create(Field.Type.DATETIME, date), true, Types.VARCHAR, datetimeFormat.format(date) },
            { Field.create(Field.Type.TIME, date), true, Types.VARCHAR, timeFormat.format(date) },
            { Field.create(Field.Type.DECIMAL, BigDecimal.valueOf(1.5)), true, Types.DECIMAL,
                    new BigDecimal(BigInteger.valueOf(15), 1, new MathContext(2, RoundingMode.FLOOR)) },
            { Field.create(Field.Type.STRING, "StreamSets"), true, Types.VARCHAR, "StreamSets" },
            { Field.create(Field.Type.BYTE_ARRAY, new byte[] { (byte) 0x00 }), true, Types.BINARY,
                    new byte[] { (byte) 0x00 } },
            { Field.create(Field.Type.MAP, Collections.emptyMap()), false, 0, null },
            { Field.create(Field.Type.LIST, Collections.emptyList()), false, 0, null },
            { Field.create(Field.Type.LIST_MAP, new LinkedHashMap<>()), false, 0, null }, });
}

From source file:edumsg.core.commands.user.IsFollowingCommand.java

@Override
public void execute() {

    try {//  ww  w.j  a  v a  2 s  . co m
        dbConn = PostgresConnection.getDataSource().getConnection();
        dbConn.setAutoCommit(false);
        proc = dbConn.prepareCall("{? = call is_following(?,?)}");
        proc.setPoolable(true);
        proc.registerOutParameter(1, Types.BOOLEAN);
        proc.setString(2, map.get("session_id"));
        proc.setString(3, map.get("username"));
        proc.execute();

        boolean is_following = proc.getBoolean(1);

        ArrayNode usersArray = nf.arrayNode();
        root.put("app", map.get("app"));
        root.put("method", map.get("method"));
        root.put("status", "ok");
        root.put("code", "200");
        root.put("following", is_following);
        proc.close();

        root.set("following", usersArray);
        try {
            CommandsHelp.submit(map.get("app"), mapper.writeValueAsString(root), map.get("correlation_id"),
                    LOGGER);
        } catch (JsonGenerationException e) {
            LOGGER.log(Level.SEVERE, e.getMessage(), e);
        } catch (JsonMappingException e) {
            LOGGER.log(Level.SEVERE, e.getMessage(), e);
        } catch (IOException e) {
            LOGGER.log(Level.SEVERE, e.getMessage(), e);
        }

        dbConn.commit();
    } catch (PSQLException e) {
        CommandsHelp.handleError(map.get("app"), map.get("method"), e.getMessage(), map.get("correlation_id"),
                LOGGER);
        LOGGER.log(Level.SEVERE, e.getMessage(), e);
    } catch (SQLException e) {
        CommandsHelp.handleError(map.get("app"), map.get("method"), e.getMessage(), map.get("correlation_id"),
                LOGGER);
        LOGGER.log(Level.SEVERE, e.getMessage(), e);
    } finally {
        PostgresConnection.disconnect(set, proc, dbConn, null);
    }
}

From source file:edumsg.core.commands.dm.CreateConversationCommand.java

@Override
public void execute() {

    try {//from  ww  w  .j  a v  a  2  s. c  o m
        dbConn = PostgresConnection.getDataSource().getConnection();
        dbConn.setAutoCommit(true);

        proc = dbConn.prepareCall("{? = call create_conversation(?,?,?)}");

        proc.setPoolable(true);
        proc.registerOutParameter(1, Types.BOOLEAN);
        proc.setString(2, map.get("session_id"));
        proc.setString(3, map.get("username"));
        proc.setString(4, map.get("dm_text"));

        proc.execute();
        boolean sent = proc.getBoolean(1);

        if (sent) {
            root.put("app", map.get("app"));
            root.put("method", map.get("method"));
            root.put("status", "ok");
            root.put("code", "200");
            try {
                CommandsHelp.submit(map.get("app"), mapper.writeValueAsString(root), map.get("correlation_id"),
                        LOGGER);
                String cacheEntry = UserCache.userCache.get("get_conv:" + map.get("session_id"));
                if (cacheEntry != null) {
                    JSONObject cacheEntryJson = new JSONObject(cacheEntry);
                    cacheEntryJson.put("cacheStatus", "invalid");
                    //                    System.out.println("invalidated");
                    UserCache.userCache.set("get_conv:" + map.get("session_id"), cacheEntryJson.toString());
                }
                String cacheEntry1 = UserCache.userCache.get("get_convs:" + map.get("session_id"));
                if (cacheEntry1 != null) {
                    JSONObject cacheEntryJson = new JSONObject(cacheEntry1);
                    cacheEntryJson.put("cacheStatus", "invalid");
                    //                    System.out.println("invalidated");
                    UserCache.userCache.set("get_convs:" + map.get("session_id"), cacheEntryJson.toString());
                }
            } catch (JsonGenerationException e) {
                LOGGER.log(Level.SEVERE, e.getMessage(), e);
            } catch (JsonMappingException e) {
                LOGGER.log(Level.SEVERE, e.getMessage(), e);
            } catch (IOException e) {
                LOGGER.log(Level.SEVERE, e.getMessage(), e);
            }
            //                catch (JSONException e) {
            //                    e.printStackTrace();
            //                }
        } else {
            CommandsHelp.handleError(map.get("app"), map.get("method"),
                    "Username Invalid or Conversation already exists", map.get("correlation_id"), LOGGER);
        }

    } catch (PSQLException e) {
        if (e.getMessage().contains("value too long")) {
            CommandsHelp.handleError(map.get("app"), map.get("method"), "DM length cannot exceed 140 character",
                    map.get("correlation_id"), LOGGER);
        } else {
            CommandsHelp.handleError(map.get("app"), map.get("method"), e.getMessage(),
                    map.get("correlation_id"), LOGGER);
        }

        LOGGER.log(Level.SEVERE, e.getMessage(), e);
    } catch (SQLException e) {
        CommandsHelp.handleError(map.get("app"), map.get("method"), e.getMessage(), map.get("correlation_id"),
                LOGGER);
        LOGGER.log(Level.SEVERE, e.getMessage(), e);
    } finally {
        PostgresConnection.disconnect(null, proc, dbConn);
    }
}

From source file:com.redsqirl.workflow.utils.jdbc.GenericConfFile.java

public GenericConfFile(String name, Connection conn) throws SQLException {
    dictionaryName = name;/*w w  w. j  av a  2  s  .c o m*/

    databaseMetaData = conn.getMetaData();

    typeRecognized = new LinkedHashMap<Integer, FieldType>();
    typeRecognized.put(Types.BOOLEAN, FieldType.BOOLEAN);
    typeRecognized.put(Types.DATE, FieldType.DATETIME);
    typeRecognized.put(Types.TIME, FieldType.DATETIME);
    typeRecognized.put(Types.DOUBLE, FieldType.DOUBLE);
    typeRecognized.put(Types.NUMERIC, FieldType.DOUBLE);
    typeRecognized.put(Types.DECIMAL, FieldType.DOUBLE);
    typeRecognized.put(Types.REAL, FieldType.DOUBLE);
    typeRecognized.put(Types.FLOAT, FieldType.FLOAT);
    typeRecognized.put(Types.INTEGER, FieldType.INT);
    typeRecognized.put(Types.SMALLINT, FieldType.INT);
    typeRecognized.put(Types.TINYINT, FieldType.INT);
    typeRecognized.put(Types.BIGINT, FieldType.LONG);
    typeRecognized.put(Types.VARCHAR, FieldType.STRING);
    typeRecognized.put(Types.CHAR, FieldType.STRING);
    typeRecognized.put(Types.LONGVARCHAR, FieldType.STRING);
    typeRecognized.put(Types.NVARCHAR, FieldType.STRING);
    typeRecognized.put(Types.NCHAR, FieldType.STRING);
    typeRecognized.put(Types.LONGNVARCHAR, FieldType.STRING);
    typeRecognized.put(Types.TIMESTAMP, FieldType.TIMESTAMP);

}