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:edumsg.core.commands.dm.CreateDm2Command.java

@Override
public void execute() {

    try {/* w w  w  .j a v a  2  s  .co m*/
        dbConn = PostgresConnection.getDataSource().getConnection();
        dbConn.setAutoCommit(true);

        if (map.containsKey("image_url")) {
            proc = dbConn.prepareCall("{? = call create_dm2(?,?,?,?)}");
        } else {
            proc = dbConn.prepareCall("{? = call create_dm2(?,?,?)}");
        }
        proc.setPoolable(true);
        proc.registerOutParameter(1, Types.BOOLEAN);
        proc.setString(2, map.get("session_id"));
        proc.setInt(3, Integer.parseInt(map.get("conv_id")));
        proc.setString(4, map.get("dm_text"));
        if (map.containsKey("image_url"))
            proc.setString(5, map.get("image_url"));
        proc.execute();

        boolean sent = proc.getBoolean(1);
        System.out.println("Result = " + map.get("conv_id"));
        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 = Cache.userCache.get("get_conv");
                //                    if (cacheEntry != null) {
                //                        JSONObject cacheEntryJson = new JSONObject(cacheEntry);
                //                        cacheEntryJson.put("cacheStatus", "invalid");
                ////                    System.out.println("invalidated");
                //                        Cache.userCache.set("get_conv", cacheEntryJson.toString());
                //                    }
                //                    String cacheEntry1 = Cache.userCache.get("get_convs");
                //                    if (cacheEntry1 != null) {
                //                        JSONObject cacheEntryJson = new JSONObject(cacheEntry1);
                //                        cacheEntryJson.put("cacheStatus", "invalid");
                ////                    System.out.println("invalidated");
                //                        Cache.userCache.set("get_convs", 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"),
                    "You can not dm a user who is not following you", 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.trackplus.ddl.GenericStringValueConverter.java

protected String extractColumnValue(ResultSet resultSet, int columnIdx, int jdbcType)
        throws SQLException, DDLException {
    String value = resultSet.getString(columnIdx);
    if (value != null) {
        switch (jdbcType) {
        case Types.NUMERIC:
        case Types.DECIMAL:
            break;
        case Types.BIT:
        case Types.BOOLEAN:
        case Types.TINYINT:
        case Types.SMALLINT:
        case Types.INTEGER:
        case Types.BIGINT:
        case Types.REAL:
        case Types.FLOAT:
        case Types.DOUBLE: {
            break;
        }//  www  . j  a v a  2 s  .  co  m

        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.TIME:
        case Types.CLOB:
        case Types.ARRAY:
        case Types.REF: {
            value = "'" + value.replaceAll("'", "''") + "'";
            break;
        }
        case Types.DATE:
        case Types.TIMESTAMP: {
            Date d = resultSet.getDate(columnIdx);
            Calendar cal = Calendar.getInstance();
            cal.setTime(d);
            int year = cal.get(Calendar.YEAR);
            if (year < 1900) {
                throw new DDLException("Invalid date:" + d);
            } else {
                value = "'" + value + "'";
            }
            break;
        }
        case Types.BLOB:
        case Types.LONGVARBINARY: {
            Blob blobValue = resultSet.getBlob(columnIdx);
            String str = new String(Base64.encodeBase64(blobValue.getBytes(1l, (int) blobValue.length())));
            value = "'" + str + "'";
            break;
        }
        default:
            break;
        }
    }
    return value;
}

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

@Override
public void execute() {

    try {//from  w w  w  .  j  ava 2s  . c  om
        dbConn = PostgresConnection.getDataSource().getConnection();
        dbConn.setAutoCommit(true);

        if (map.containsKey("image_url")) {
            proc = dbConn.prepareCall("{? = call create_dm(?,?,?,now()::timestamp,?)}");
        } else {
            proc = dbConn.prepareCall("{? = call create_dm(?,?,?,now()::timestamp)}");
        }
        proc.setPoolable(true);
        proc.registerOutParameter(1, Types.BOOLEAN);
        proc.setString(2, map.get("session_id"));
        proc.setInt(3, Integer.parseInt(map.get("receiver_id")));
        proc.setString(4, map.get("dm_text"));
        if (map.containsKey("image_url"))
            proc.setString(5, map.get("image_url"));
        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"),
                    "You can not dm a user who is not following you", 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.draagon.meta.manager.db.driver.MSSQLDriver.java

/**
 * Creates a table in the database// w  w w .j  a va2  s  .  com
 */
@Override
public void createTable(Connection c, TableDef table) throws SQLException {
    String query = "CREATE TABLE [" + table + "] (\n";

    boolean multi = (table.getPrimaryKeys().size() > 1);

    boolean hasIdentity = false;

    // Create the individual table fields
    int found = 0;
    for (ColumnDef col : table.getColumns()) {
        String name = col.getName();
        if (name == null || name.length() == 0) {
            throw new IllegalArgumentException("No name defined for column [" + col + "]");
        }

        if (found > 0)
            query += ",\n";
        found++;

        String flags = "";
        if (col.isPrimaryKey() && !multi)
            flags = "PRIMARY KEY ";
        else if (col.isUnique())
            flags = "UNIQUE ";
        //else if (getManager().isIndex(mf)) flags = "NONCLUSTERED ";

        switch (col.getSQLType()) {
        case Types.BOOLEAN:
        case Types.BIT:
            query += "[" + name + "] [bit] " + flags;
            break;
        case Types.TINYINT:
            query += "[" + name + "] [tinyint] " + flags;
            break;
        case Types.SMALLINT:
            query += "[" + name + "] [smallint] " + flags;
            break;
        case Types.INTEGER:
            query += "[" + name + "] [int] " + flags;
            break;
        case Types.BIGINT:
            query += "[" + name + "] [bigint] " + flags;
            break;
        case Types.FLOAT:
            query += "[" + name + "] [float] " + flags;
            break;
        case Types.DOUBLE:
            query += "[" + name + "] [decimal](19,4) " + flags;
            break;
        case Types.TIMESTAMP:
            query += "[" + name + "] [datetime] " + flags;
            break;
        case Types.VARCHAR:
            query += "[" + name + "] [varchar](" + col.getLength() + ") " + flags;
            break;

        default:
            throw new IllegalArgumentException("Table [" + table + "] with Column [" + col
                    + "] is of SQL type (" + col.getSQLType() + ") which is not support by this database");
        }

        // Create the identity columns
        if (col.isAutoIncrementor()) {
            if (hasIdentity)
                throw new MetaException(
                        "Table [" + table + "] cannot have multiple identity (auto id) columns!");

            query += "NOT NULL IDENTITY( " + col.getSequence().getStart() + ", "
                    + col.getSequence().getIncrement() + " ) ";

            hasIdentity = true;
        }
    }

    query += "\n)";

    // This means there were no columns defined for the table
    if (found == 0)
        return;

    if (log.isDebugEnabled()) {
        log.debug("Creating table [" + table + "]: " + query);
    }
    //ystem.out.println( ">>>> Creating table [" + table + "]: " + query);

    Statement s = c.createStatement();
    try {
        s.execute(query);
    } finally {
        s.close();
    }
}

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

@Parameterized.Parameters(name = "type({0})")
public static Collection<Object[]> data() throws Exception {
    return Arrays.asList(new Object[][] {
            // Primitive types
            { "\"boolean\"", true, true, "BOOLEAN", Types.BOOLEAN, "0" },
            { "\"int\"", Integer.MIN_VALUE, Integer.MIN_VALUE, "INT", Types.INTEGER, "0" },
            { "\"long\"", Long.MAX_VALUE, Long.MAX_VALUE, "BIGINT", Types.BIGINT, "0" },
            // From some reason type is FLOAT, but returned object is double
            { "\"float\"", Float.NaN, Double.NaN, "FLOAT", Types.FLOAT, "0" },
            { "\"double\"", Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, "DOUBLE", Types.DOUBLE, "0" },
            { "\"bytes\"", ByteBuffer.wrap(new byte[] { (byte) 0x00, (byte) 0xFF }),
                    new byte[] { (byte) 0x00, (byte) 0xFF }, "BINARY", Types.BINARY, "1.0" },
            { "\"string\"", new Utf8("StreamSets"), "StreamSets", "STRING", Types.VARCHAR, "1.0" },

            // Complex types are skipped for now

            // Logical types
            { DECIMAL.toString(), ByteBuffer.wrap(new byte[] { (byte) 0x0F }), new BigDecimal("2"), "DECIMAL",
                    Types.DECIMAL, "0" },
            { DATE.toString(), 17039, new java.sql.Date(116, 7, 26), "DATE", Types.DATE, "1.2" }, });
}

From source file:org.sonar.db.version.BaseSqlStatement.java

@Override
public CHILD setBoolean(int columnIndex, @Nullable Boolean value) throws SQLException {
    if (value == null) {
        pstmt.setNull(columnIndex, Types.BOOLEAN);
    } else {/*from   w  w  w.j  ava 2 s . c o m*/
        pstmt.setBoolean(columnIndex, value);
    }
    return (CHILD) this;
}

From source file:org.talend.dataquality.record.linkage.ui.composite.table.SortComparator.java

public static ISortComparator getSortComparator(int javaDataType) throws ParseException {
    switch (javaDataType) {
    case Types.DATE:
    case Types.TIME:
        return new SortComparator() {

            @Override/*from  w  ww  .ja v  a  2s  .  c om*/
            public int compareNotNull(Object value1, Object value2) throws ParseException {
                return java.sql.Date.valueOf(value1.toString())
                        .compareTo(java.sql.Date.valueOf(value2.toString()));
            }

        };
    case Types.TIMESTAMP:
        return new SortComparator() {

            @Override
            public int compareNotNull(Object value1, Object value2) throws ParseException {
                return Timestamp.valueOf(value1.toString()).compareTo(Timestamp.valueOf(value2.toString()));
            }

        };
    case Types.DOUBLE:
    case Types.REAL:
    case Types.FLOAT:
        return new SortComparator() {

            @Override
            public int compareNotNull(Object value1, Object value2) throws ParseException {
                return Double.valueOf(value1.toString()).compareTo(Double.valueOf(value2.toString()));
            }

        };

    case Types.INTEGER:
    case Types.TINYINT:
    case Types.SMALLINT:
    case Types.NUMERIC:

        return new SortComparator() {

            @Override
            public int compareNotNull(Object value1, Object value2) throws ParseException {
                return Integer.valueOf(value1.toString()).compareTo(Integer.valueOf(value2.toString()));
            }

        };
    case Types.BIGINT:
        return new SortComparator() {

            @Override
            public int compareNotNull(Object value1, Object value2) throws ParseException {
                return Long.valueOf(value1.toString()).compareTo(Long.valueOf(value2.toString()));
            }

        };
    case Types.DECIMAL:
        return new SortComparator() {

            @Override
            public int compareNotNull(Object value1, Object value2) throws ParseException {
                if (value1 instanceof BigDecimal) {
                    return ((BigDecimal) value1).compareTo((BigDecimal) value2);
                }
                BigDecimal b1 = new BigDecimal(value1.toString());
                BigDecimal b2 = new BigDecimal(value2.toString());
                return b1.compareTo(b2);
            }

        };
    case Types.BOOLEAN:
    case Types.BIT:
        return new SortComparator() {

            @Override
            public int compareNotNull(Object value1, Object value2) throws ParseException {
                return Boolean.valueOf(value1.toString()).compareTo(Boolean.valueOf(value2.toString()));
            }

        };
    default:// String
        return new SortComparator() {

            @Override
            public int compareNotNull(Object value1, Object value2) throws ParseException {
                return value1.toString().compareTo(value2.toString());
            }

        };

    }

}

From source file:com.nabla.wapp.server.json.SqlColumn.java

public void write(final ResultSet rs, int column, final JSONObject record) throws SQLException {
    switch (type) {
    case Types.BIGINT:
    case Types.INTEGER:
    case Types.SMALLINT:
    case Types.TINYINT:
        record.put(label, rs.getInt(column));
        break;/*from   w  w  w  . j a va 2s  . c o  m*/
    case Types.BOOLEAN:
    case Types.BIT:
        record.put(label, rs.getBoolean(column));
        break;
    case Types.DATE:
        final Date dt = rs.getDate(column);
        if (rs.wasNull())
            record.put(label, null);
        else
            record.put(label, new JSonDate(dt));
        return;
    case Types.TIMESTAMP:
        final Timestamp tm = rs.getTimestamp(column);
        if (rs.wasNull())
            record.put(label, null);
        else
            record.put(label, timeStampFormat.format(tm));
        return;
    case Types.DOUBLE:
        record.put(label, rs.getDouble(column));
        break;
    case Types.FLOAT:
        record.put(label, rs.getFloat(column));
        break;
    case Types.NULL:
        record.put(label, null);
        return;
    default:
        record.put(label, rs.getString(column));
        break;
    }
    if (rs.wasNull())
        record.put(label, null);
}

From source file:com.thinkbiganalytics.discovery.util.ParserHelper.java

public static String sqlTypeToHiveType(Integer type) {
    switch (type) {
    case Types.BIGINT:
        return "bigint";
    case Types.NUMERIC:
    case Types.DOUBLE:
    case Types.DECIMAL:
        return "double";
    case Types.INTEGER:
        return "int";
    case Types.FLOAT:
        return "float";
    case Types.TINYINT:
        return "tinyint";
    case Types.DATE:
        return "date";
    case Types.TIMESTAMP:
        return "timestamp";
    case Types.BOOLEAN:
        return "boolean";
    case Types.BINARY:
        return "binary";
    default:/*w  ww. j av a  2 s . co  m*/
        return "string";
    }
}

From source file:uk.ac.ebi.bioinvindex.utils.test.H2DataTypeFactory.java

public DataType createDataType(int sqlType, String sqlTypeName) throws DataTypeException {
    if (sqlType == Types.BOOLEAN) {
        return DataType.BOOLEAN;
    }/*from ww w  .  j  a v a 2  s .  c  o m*/

    // BLOB
    if ("BLOB".equals(sqlTypeName)) {
        return BLOB_AS_STREAM;
    }

    // CLOB
    if ("CLOB".equals(sqlTypeName)) {
        return CLOB_AS_STRING;
    }

    return super.createDataType(sqlType, sqlTypeName);
}