Example usage for java.sql Types INTEGER

List of usage examples for java.sql Types INTEGER

Introduction

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

Prototype

int INTEGER

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

Click Source Link

Document

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

Usage

From source file:org.owasp.proxy.http.dao.JdbcMessageDAO.java

public Conversation getConversation(int id) throws DataAccessException {
    try {/*from  ww  w .  j a v  a2  s. c o m*/
        MapSqlParameterSource params = new MapSqlParameterSource();
        params.addValue(ID, id, Types.INTEGER);
        SimpleJdbcTemplate template = new SimpleJdbcTemplate(getNamedParameterJdbcTemplate());
        return template.queryForObject(SELECT_SUMMARY, CONVERSATION_MAPPER, params);
    } catch (EmptyResultDataAccessException erdae) {
        return null;
    }
}

From source file:com.nextep.designer.sqlclient.ui.connectors.SQLResultConnector.java

private void initializeTable(ISQLQuery query, long executionTime, INextepMetadata md) {
    colMaxWidth = new int[md.getColumnCount() + 1];
    // Checking columns to display
    int displayedColumns = query.getDisplayedColumnsCount();
    if (displayedColumns <= 0) {
        displayedColumns = md.getColumnCount();
    }//from   w  ww  . j  ava  2s  . c o  m
    for (int i = 1; i <= displayedColumns; i++) {
        final String colName = md.getColumnName(i);
        // final int colPrecision = md.getPrecision(index);
        final int colType = md.getColumnType(i);

        final int colIndex = i - 1;
        if (!sqlView.isDisposed()) {
            TableColumn c = new TableColumn(sqlView, SWT.NONE);
            c.setText(colName);
            c.setWidth(colName.length() * 8);
            c.addListener(SWT.Selection, comparator);
            colMaxWidth[colIndex] = c.getWidth();
            SQLResultLabelProvider lblProvider = new SQLResultLabelProvider(this, colIndex);
            final TableViewerColumn viewerCol = new TableViewerColumn(sqlViewer, c);
            viewerCol.setLabelProvider(lblProvider);
            // Registering column comparator
            switch (colType) {
            case Types.BIGINT:
            case Types.BIT:
            case Types.DECIMAL:
            case Types.DOUBLE:
            case Types.FLOAT:
            case Types.INTEGER:
            case Types.NUMERIC:
            case Types.REAL:
            case Types.SMALLINT:
            case Types.TINYINT:
                c.setData(SQLResultViewerComparator.KEY_COMPARATOR, new NumberComparator());
                // Setting our deserializer which can produce number from string
                c.setData(KEY_DESERIALIZER, NUMBER_DESERIALIZER);
                break;
            case Types.DATE:
            case Types.TIME:
            case Types.TIMESTAMP:
                // Defines validation so that user will be notified about problems
                c.setData(KEY_CELL_VALIDATOR, DATE_VALIDATOR);
                // Setting our deserializer which can produce date from string
                c.setData(KEY_DESERIALIZER, DATE_DESERIALIZER);
                c.setData(SQLResultViewerComparator.KEY_COMPARATOR, new DateComparator());
                break;
            default:
                c.setData(KEY_DESERIALIZER, STRING_DESERIALIZER);
                c.setData(SQLResultViewerComparator.KEY_COMPARATOR, new StringComparator());
            }
        }
    }
    registerCellEditors();
    setStatusLabel(MessageFormat.format(SQLClientMessages.getString("sql.executionTime"), executionTime),
            false);
    sqlViewer.setInput(query.getResult());
}

From source file:com.zimbra.cs.db.DbMailItem.java

public void create(UnderlyingData data) throws ServiceException {
    if (data.id <= 0 || data.folderId <= 0 || data.parentId == 0) {
        throw ServiceException.FAILURE("invalid data for DB item create", null);
    }/*from  w w w.ja  v  a 2  s. c o  m*/
    assert mailbox.isNewItemIdValid(data.id) : "[bug 46549] illegal id for mail item"; //temporarily for bug 46549
    checkNamingConstraint(mailbox, data.folderId, data.name, data.id);

    DbConnection conn = mailbox.getOperationConnection();
    PreparedStatement stmt = null;
    try {
        MailItem.Type type = MailItem.Type.of(data.type);

        stmt = conn.prepareStatement("INSERT INTO " + getMailItemTableName(mailbox) + "(" + MAILBOX_ID
                + " id, type, parent_id, folder_id, index_id, imap_id, date, size, locator, blob_digest, unread,"
                + " flags, tag_names, sender, recipients, subject, name, metadata, mod_metadata, change_date,"
                + " mod_content, uuid) VALUES (" + MAILBOX_ID_VALUE
                + "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
        int pos = 1;
        pos = setMailboxId(stmt, mailbox, pos);
        stmt.setInt(pos++, data.id);
        stmt.setByte(pos++, data.type);
        if (data.parentId <= 0) {
            // Messages in virtual conversations are stored with a null parent_id
            stmt.setNull(pos++, Types.INTEGER);
        } else {
            stmt.setInt(pos++, data.parentId);
        }
        stmt.setInt(pos++, data.folderId);
        if (data.indexId == MailItem.IndexStatus.NO.id()) {
            stmt.setNull(pos++, Types.INTEGER);
        } else {
            stmt.setInt(pos++, data.indexId);
        }
        if (data.imapId <= 0) {
            stmt.setNull(pos++, Types.INTEGER);
        } else {
            stmt.setInt(pos++, data.imapId);
        }
        stmt.setInt(pos++, data.date);
        stmt.setLong(pos++, data.size);
        stmt.setString(pos++, data.locator);
        stmt.setString(pos++, data.getBlobDigest());
        switch (type) {
        case MESSAGE:
        case CHAT:
        case FOLDER:
            stmt.setInt(pos++, data.unreadCount);
            break;
        default:
            stmt.setNull(pos++, Types.INTEGER);
            break;
        }
        stmt.setInt(pos++, data.getFlags());
        stmt.setString(pos++, DbTag.serializeTags(data.getTags()));
        stmt.setString(pos++, sender);
        stmt.setString(pos++, recipients);
        stmt.setString(pos++, data.getSubject());
        stmt.setString(pos++, data.name);
        stmt.setString(pos++, checkMetadataLength(data.metadata));
        stmt.setInt(pos++, data.modMetadata);
        if (data.dateChanged > 0) {
            stmt.setInt(pos++, data.dateChanged);
        } else {
            stmt.setNull(pos++, Types.INTEGER);
        }
        stmt.setInt(pos++, data.modContent);
        stmt.setString(pos++, data.uuid);
        int num = stmt.executeUpdate();
        if (num != 1) {
            throw ServiceException.FAILURE("failed to create object", null);
        }

        DbTag.storeTagReferences(mailbox, data.id, type, data.getFlags(), data.unreadCount > 0);
        DbTag.storeTagReferences(mailbox, data.id, type, data.getTags());
    } catch (SQLException e) {
        // catch item_id uniqueness constraint violation and return failure
        if (Db.errorMatches(e, Db.Error.DUPLICATE_ROW)) {
            throw MailServiceException.ALREADY_EXISTS(data.id, e);
        } else {
            throw ServiceException.FAILURE("Failed to create id=" + data.id + ",type=" + data.type, e);
        }
    } finally {
        DbPool.closeStatement(stmt);
    }
}

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

private String getTypeName(int SQLType) {
    switch (SQLType) {
    case Types.ARRAY:
        return "ARRAY";
    case Types.BIGINT:
        return "INTEGER";
    case Types.BINARY:
        return "BINARY";
    case Types.BIT:
        return "BIT";
    case Types.BLOB:
        return "BLOB";
    case Types.BOOLEAN:
        return "BOOLEAN";
    case Types.CHAR:
        return "CHAR";
    case Types.CLOB:
        return "CLOB";
    case Types.DATALINK:
        return "DATALINK";
    case Types.DATE:
        return "DATE";
    case Types.DECIMAL:
        return "DECIMAL";
    case Types.DOUBLE:
        return "DOUBLE";
    case Types.FLOAT:
        return "FLOAT";
    case Types.INTEGER:
        return "INTEGER";
    case Types.JAVA_OBJECT:
        return "JAVA_OBJECT";
    case Types.LONGNVARCHAR:
        return "LONGNVARCHAR";
    case Types.LONGVARBINARY:
        return "LONGVARBINARY";
    case Types.NCHAR:
        return "NCHAR";
    case Types.NCLOB:
        return "NCLOB";
    case Types.NULL:
        return "UNDEFINED";//
    case Types.NUMERIC:
        return "NUMERIC";
    case Types.NVARCHAR:
        return "NVARCHAR";
    case Types.OTHER:
        return "UNDEFINED";//
    case Types.REAL:
        return "REAL";
    case Types.REF:
        return "REF";
    case Types.ROWID:
        return "ROWID";
    case Types.SMALLINT:
        return "SMALLINT";
    case Types.SQLXML:
        return "SQLXML";
    case Types.STRUCT:
        return "STRUCT";
    case Types.TIME:
        return "TIME";
    case Types.TIMESTAMP:
        return "TIMESTAMP";
    case Types.TINYINT:
        return "TINYINT";
    case Types.VARBINARY:
        return "VARBINARY";
    case Types.VARCHAR:
        return "VARCHAR";
    default://from w w w. j  a v a2 s  .  c om
        return "UNDEFINED";//
    }
}

From source file:ca.sqlpower.matchmaker.address.AddressPool.java

/**
 * Builds a result table specifically configured for Address Correction
 * projects. Note that this only builds the SQLTable object representing the
 * result table. It does not execute the SQL statements necessary to create
 * such a table in a database.//from   w w w  .j av  a 2 s  .  co m
 * 
 * TODO: the column widths are hard-coded magic values! Refactor to constants.
 * TODO: this method belongs in another class.
 * 
 * @param resultTable
 * @param si
 * @param session This is used in getting the UserDefinedSQLTypes from the PlDotIni
 * @return A {@link SQLTable} representing the result table.
 */
public static SQLTable buildAddressCorrectionResultTable(SQLTable resultTable, SQLIndex si,
        MatchMakerSession session) throws SQLObjectException {
    SQLTable t = new SQLTable(resultTable.getParent(), resultTable.getName(), resultTable.getRemarks(), "TABLE",
            true);

    for (int i = 0; i < si.getChildCount(); i++) {
        SQLColumn idxCol = ((Column) si.getChild(i)).getColumn();
        SQLColumn newCol = new SQLColumn(t, SOURCE_ADDRESS_KEY_COLUMN_BASE + i,
                session.getSQLType(idxCol.getType()), idxCol.getPrecision(), idxCol.getScale(), false);
        t.addColumn(newCol);
    }

    SQLColumn inputAddressLine1 = new SQLColumn(t, INPUT_ADDRESS_LINE1, session.getSQLType(Types.VARCHAR), 70,
            0, false);
    t.addColumn(inputAddressLine1);
    SQLColumn inputAddressLine2 = new SQLColumn(t, INPUT_ADDRESS_LINE2, session.getSQLType(Types.VARCHAR), 70,
            0, false);
    t.addColumn(inputAddressLine2);
    SQLColumn inputMunicipality = new SQLColumn(t, INPUT_MUNICIPALITY, session.getSQLType(Types.VARCHAR), 30, 0,
            false);
    t.addColumn(inputMunicipality);
    SQLColumn inputProvince = new SQLColumn(t, INPUT_PROVINCE, session.getSQLType(Types.VARCHAR), 30, 0, false);
    t.addColumn(inputProvince);
    SQLColumn inputCountry = new SQLColumn(t, INPUT_COUNTRY, session.getSQLType(Types.VARCHAR), 30, 0, false);
    t.addColumn(inputCountry);
    SQLColumn inputPostalCode = new SQLColumn(t, INPUT_POSTAL_CODE, session.getSQLType(Types.VARCHAR), 10, 0,
            false);
    t.addColumn(inputPostalCode);

    SQLColumn outputCountry = new SQLColumn(t, OUTPUT_COUNTRY, session.getSQLType(Types.VARCHAR), 30, 0, false);
    t.addColumn(outputCountry);
    SQLColumn outputDeliveryInstallationName = new SQLColumn(t, OUTPUT_DELIVERY_INSTALLATION_NAME,
            session.getSQLType(Types.VARCHAR), 50, 0, false);
    t.addColumn(outputDeliveryInstallationName);
    SQLColumn outputDeliveryInstallationType = new SQLColumn(t, OUTPUT_DELIVERY_INSTALLATION_TYPE,
            session.getSQLType(Types.VARCHAR), 5, 0, false);
    t.addColumn(outputDeliveryInstallationType);
    SQLColumn outputDirectionPrefix = new SQLColumn(t, OUTPUT_DIRECTION_PREFIX,
            session.getSQLType(Types.BOOLEAN), 0, 0, false);
    t.addColumn(outputDirectionPrefix);
    SQLColumn outputFailedParsingString = new SQLColumn(t, OUTPUT_FAILED_PARSING_STRING,
            session.getSQLType(Types.VARCHAR), 150, 0, false);
    t.addColumn(outputFailedParsingString);
    SQLColumn outputGeneralDeliveryName = new SQLColumn(t, OUTPUT_GENERAL_DELIVERY_NAME,
            session.getSQLType(Types.VARCHAR), 70, 0, false);
    t.addColumn(outputGeneralDeliveryName);
    SQLColumn outputLockBoxNumber = new SQLColumn(t, OUTPUT_LOCK_BOX_NUMBER, session.getSQLType(Types.VARCHAR),
            5, 0, false);
    t.addColumn(outputLockBoxNumber);
    SQLColumn outputLockBoxType = new SQLColumn(t, OUTPUT_LOCK_BOX_TYPE, session.getSQLType(Types.VARCHAR), 6,
            0, false);
    t.addColumn(outputLockBoxType);
    SQLColumn outputMunicipality = new SQLColumn(t, OUTPUT_MUNICIPALITY, session.getSQLType(Types.VARCHAR), 30,
            0, false);
    t.addColumn(outputMunicipality);
    SQLColumn outputPostalCode = new SQLColumn(t, OUTPUT_POSTAL_CODE, session.getSQLType(Types.VARCHAR), 10, 0,
            false);
    t.addColumn(outputPostalCode);
    SQLColumn outputProvince = new SQLColumn(t, OUTPUT_PROVINCE, session.getSQLType(Types.VARCHAR), 30, 0,
            false);
    t.addColumn(outputProvince);
    SQLColumn outputRuralRouteNumber = new SQLColumn(t, OUTPUT_RURAL_ROUTE_NUMBER,
            session.getSQLType(Types.VARCHAR), 5, 0, false);
    t.addColumn(outputRuralRouteNumber);
    SQLColumn outputRuralRouteType = new SQLColumn(t, OUTPUT_RURAL_ROUTE_TYPE,
            session.getSQLType(Types.VARCHAR), 2, 0, false);
    t.addColumn(outputRuralRouteType);
    SQLColumn outputStreetDirection = new SQLColumn(t, OUTPUT_STREET_DIRECTION,
            session.getSQLType(Types.VARCHAR), 5, 0, false);
    t.addColumn(outputStreetDirection);
    SQLColumn outputStreetName = new SQLColumn(t, OUTPUT_STREET_NAME, session.getSQLType(Types.VARCHAR), 30, 0,
            false);
    t.addColumn(outputStreetName);
    SQLColumn outputStreetNumber = new SQLColumn(t, OUTPUT_STREET_NUMBER, session.getSQLType(Types.INTEGER), 0,
            0, false);
    t.addColumn(outputStreetNumber);
    SQLColumn outputStreetNumberSuffix = new SQLColumn(t, OUTPUT_STREET_NUMBER_SUFFIX,
            session.getSQLType(Types.VARCHAR), 6, 0, false);
    t.addColumn(outputStreetNumberSuffix);
    SQLColumn outputStreetNumberSuffixSeparate = new SQLColumn(t, OUTPUT_STREET_NUMBER_SUFFIX_SEPARATE,
            session.getSQLType(Types.BOOLEAN), 0, 0, false);
    t.addColumn(outputStreetNumberSuffixSeparate);
    SQLColumn outputStreetType = new SQLColumn(t, OUTPUT_STREET_TYPE, session.getSQLType(Types.VARCHAR), 11, 0,
            false);
    t.addColumn(outputStreetType);
    SQLColumn outputStreetTypePrefix = new SQLColumn(t, OUTPUT_STREET_TYPE_PREFIX,
            session.getSQLType(Types.BOOLEAN), 0, 0, false);
    t.addColumn(outputStreetTypePrefix);
    SQLColumn outputSuite = new SQLColumn(t, OUTPUT_SUITE, session.getSQLType(Types.VARCHAR), 6, 0, false);
    t.addColumn(outputSuite);
    SQLColumn outputSuitePrefix = new SQLColumn(t, OUTPUT_SUITE_PREFIX, session.getSQLType(Types.VARCHAR), 1, 0,
            false);
    t.addColumn(outputSuitePrefix);
    SQLColumn outputSuiteType = new SQLColumn(t, OUTPUT_SUITE_TYPE, session.getSQLType(Types.VARCHAR), 15, 0,
            false);
    t.addColumn(outputSuiteType);
    SQLColumn outputUnparsedAddress = new SQLColumn(t, OUTPUT_UNPARSED_ADDRESS,
            session.getSQLType(Types.VARCHAR), 150, 0, false);
    t.addColumn(outputUnparsedAddress);
    SQLColumn outputType = new SQLColumn(t, OUTPUT_TYPE, session.getSQLType(Types.VARCHAR), 20, 0, false);
    t.addColumn(outputType);
    SQLColumn outputUrbanBeforeRural = new SQLColumn(t, OUTPUT_URBAN_BEFORE_RURAL,
            session.getSQLType(Types.BOOLEAN), 0, 0, false);
    t.addColumn(outputUrbanBeforeRural);
    SQLColumn valid = new SQLColumn(t, OUTPUT_VALID, session.getSQLType(Types.BOOLEAN), 0, 0, false);
    t.addColumn(valid);

    SQLIndex newidx = new SQLIndex(t.getName() + "_uniq", true, null, null, null);
    for (int i = 0; i < si.getChildCount(); i++) {
        newidx.addChild(new Column(t.getColumn(i), AscendDescend.ASCENDING));
    }
    t.addIndex(newidx);

    return t;
}

From source file:ca.sqlpower.sqlobject.TestSQLTable.java

/** this tests for a real bug.. the column was showing up one index above the end of the pk  */
public void testAddColumnAtEndOfPK() throws SQLObjectException {
    SQLTable t = new SQLTable(null, true);
    t.setName("Test Table");
    SQLColumn pk1 = new SQLColumn(t, "PKColumn1", Types.INTEGER, 10, 0);
    SQLColumn pk2 = new SQLColumn(t, "PKColumn2", Types.INTEGER, 10, 0);
    SQLColumn pk3 = new SQLColumn(t, "PKColumn3", Types.INTEGER, 10, 0);
    SQLColumn at1 = new SQLColumn(t, "AT1", Types.INTEGER, 10, 0);
    SQLColumn at2 = new SQLColumn(t, "AT2", Types.INTEGER, 10, 0);
    SQLColumn at3 = new SQLColumn(t, "AT3", Types.INTEGER, 10, 0);

    t.addColumn(pk1, 0);/*from  ww w . j av a 2 s. c  o m*/
    t.addColumn(pk2, 1);
    t.addColumn(pk3, 2);
    t.addColumn(at1, 3);
    t.addColumn(at2, 4);
    t.addColumn(at3, 5);

    t.getPrimaryKeyIndex().addIndexColumn(pk1);
    t.getPrimaryKeyIndex().addIndexColumn(pk2);
    t.getPrimaryKeyIndex().addIndexColumn(pk3);

    assertEquals(3, t.getPkSize());

    SQLColumn newcol = new SQLColumn(t, "newcol", Types.INTEGER, 10, 0);
    t.addColumn(newcol, 3);
    assertEquals("New column should be at requested position", 3, t.getColumnIndex(newcol));
    t.getPrimaryKeyIndex().addIndexColumn(newcol);
    assertEquals("New column should still be at requested position", 3, t.getColumnIndex(newcol));
}

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

public static int FromTypeName(String SQLName) {
    if (SQLName.equals("ARRAY")) {
        return Types.ARRAY;
    }/*from ww  w. j a  va  2 s  . c o  m*/
    if (SQLName.equals("INTEGER")) {
        return Types.INTEGER;
    }
    if (SQLName.equals("BINARY")) {
        return Types.BINARY;
    }
    if (SQLName.equals("BIT")) {
        return Types.BIT;
    }
    if (SQLName.equals("BLOB")) {
        return Types.BLOB;
    }
    if (SQLName.equals("BOOLEAN")) {
        return Types.BOOLEAN;
    }
    if (SQLName.equals("CHAR")) {
        return Types.CHAR;
    }
    if (SQLName.equals("CLOB")) {
        return Types.CLOB;
    }
    if (SQLName.equals("DATALINK")) {
        return Types.DATALINK;
    }
    if (SQLName.equals("DATE")) {
        return Types.DATE;
    }
    if (SQLName.equals("DECIMAL")) {
        return Types.DECIMAL;
    }
    if (SQLName.equals("DOUBLE")) {
        return Types.DOUBLE;
    }
    if (SQLName.equals("FLOAT")) {
        return Types.FLOAT;
    }
    if (SQLName.equals("JAVA_OBJECT")) {
        return Types.JAVA_OBJECT;
    }
    if (SQLName.equals("LONGNVARCHAR")) {
        return Types.LONGNVARCHAR;
    }
    if (SQLName.equals("LONGVARBINARY")) {
        return Types.LONGVARBINARY;
    }
    if (SQLName.equals("NCHAR")) {
        return Types.NCHAR;
    }
    if (SQLName.equals("NCLOB")) {
        return Types.NCLOB;
    }
    if (SQLName.equals("UNDEFINED")) {
        return Types.OTHER;
    }
    if (SQLName.equals("NUMERIC")) {
        return Types.NUMERIC;
    }
    if (SQLName.equals("NVARCHAR")) {
        return Types.NVARCHAR;
    }
    if (SQLName.equals("REAL")) {
        return Types.REAL;
    }
    if (SQLName.equals("REF")) {
        return Types.REF;
    }
    if (SQLName.equals("ROWID")) {
        return Types.ROWID;
    }
    if (SQLName.equals("SMALLINT")) {
        return Types.SMALLINT;
    }
    if (SQLName.equals("SQLXML")) {
        return Types.SQLXML;
    }
    if (SQLName.equals("STRUCT")) {
        return Types.STRUCT;
    }
    if (SQLName.equals("TIME")) {
        return Types.TIME;
    }
    if (SQLName.equals("TIMESTAMP")) {
        return Types.TIMESTAMP;
    }
    if (SQLName.equals("TINYINT")) {
        return Types.TINYINT;
    }
    if (SQLName.equals("VARCHAR")) {
        return Types.VARCHAR;
    }
    if (SQLName.equals("VARBINARY")) {
        return Types.VARBINARY;
    }
    return Types.OTHER;
}

From source file:com.micromux.cassandra.jdbc.JdbcRegressionTest.java

/**
 * Test the meta-data logic for the database. This should allow you to query the
 * schema information dynamically. Previously this was <i>Issue 40</i>.
 *///  www.  j  a  va 2 s .c o m
@Test
public void testDatabaseMetaData() throws Exception {
    DatabaseMetaData md = con.getMetaData();

    // test various retrieval methods
    ResultSet result = md.getTables(con.getCatalog(), null, "%", new String[] { "TABLE" });
    assertTrue("Make sure we have found a table", result.next());
    result = md.getTables(null, KEYSPACE, TABLE, null);
    assertTrue("Make sure we have found the table asked for", result.next());
    result = md.getTables(null, KEYSPACE, TABLE, new String[] { "TABLE" });
    assertTrue("Make sure we have found the table asked for", result.next());
    result = md.getTables(con.getCatalog(), KEYSPACE, TABLE, new String[] { "TABLE" });
    assertTrue("Make sure we have found the table asked for", result.next());

    // check the table name
    String tn = result.getString("TABLE_NAME");
    assertEquals("Table name match", TABLE, tn);
    System.out.println("Found table via dmd    :   " + tn);

    // load the columns
    result = md.getColumns(con.getCatalog(), KEYSPACE, TABLE, null);
    assertTrue("Make sure we have found first column", result.next());
    assertEquals("Make sure table name match", TABLE, result.getString("TABLE_NAME"));
    String cn = result.getString("COLUMN_NAME");
    System.out.println("Found (default) PK column       :   " + cn);
    assertEquals("Column name check", "keyname", cn);
    assertEquals("Column type check", Types.VARCHAR, result.getInt("DATA_TYPE"));
    assertTrue("Make sure we have found second column", result.next());
    cn = result.getString("COLUMN_NAME");
    System.out.println("Found column       :   " + cn);
    assertEquals("Column name check", "bvalue", cn);
    assertEquals("Column type check", Types.BOOLEAN, result.getInt("DATA_TYPE"));
    assertTrue("Make sure we have found thirth column", result.next());
    cn = result.getString("COLUMN_NAME");
    System.out.println("Found column       :   " + cn);
    assertEquals("Column name check", "ivalue", cn);
    assertEquals("Column type check", Types.INTEGER, result.getInt("DATA_TYPE"));

    // make sure we filter
    result = md.getColumns(con.getCatalog(), KEYSPACE, TABLE, "bvalue");
    result.next();
    assertFalse("Make sure we have found requested column only", result.next());
}

From source file:com.flexive.ejb.beans.LanguageBean.java

/**
 * {@inheritDoc}//w  w w .  jav  a  2s  .  c o m
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void setAvailable(List<FxLanguage> available, boolean ignoreUsage) throws FxApplicationException {
    FxPermissionUtils.checkRole(FxContext.getUserTicket(), Role.GlobalSupervisor);
    Connection con = null;
    PreparedStatement ps = null;
    if (available == null || available.size() == 0)
        throw new FxInvalidParameterException("available", "ex.language.noAvailable");
    try {
        con = Database.getDbConnection();
        if (!ignoreUsage) {
            List<FxLanguage> orgLang = loadAvailable(true);
            boolean found;
            for (FxLanguage org : orgLang) {
                found = false;
                for (FxLanguage tmp : available) {
                    if (tmp.getId() == org.getId()) {
                        found = true;
                        break;
                    }
                }
                if (!found && hasUsages(con, org))
                    throw new FxInvalidParameterException("available", "ex.language.removeUsed",
                            org.getLabel());
            }
        }
        ps = con.prepareStatement("UPDATE " + TBL_LANG + " SET INUSE=?, DISPPOS=?");
        ps.setBoolean(1, false);
        ps.setNull(2, java.sql.Types.INTEGER);
        ps.executeUpdate();
        ps.close();
        int pos = 0;
        ps = con.prepareStatement("UPDATE " + TBL_LANG + " SET INUSE=?, DISPPOS=? WHERE LANG_CODE=?");
        ps.setBoolean(1, true);
        for (FxLanguage lang : available) {
            ps.setInt(2, pos++);
            ps.setLong(3, lang.getId());
            ps.addBatch();
        }
        ps.executeBatch();
        StructureLoader.updateLanguages(FxContext.get().getDivisionId(), loadAll(true, true));
    } catch (FxCacheException e) {
        LOG.error(e, e);
    } catch (SQLException e) {
        throw new FxUpdateException(LOG, e, "ex.db.sqlError", e.getMessage());
    } finally {
        Database.closeObjects(LanguageBean.class, con, ps);
    }
}

From source file:org.owasp.proxy.http.dao.JdbcMessageDAO.java

public byte[] loadMessageContent(int id) throws DataAccessException {
    try {//from  www .  j ava 2s  .c  o  m
        MapSqlParameterSource params = new MapSqlParameterSource();
        params.addValue(ID, id, Types.INTEGER);
        SimpleJdbcTemplate template = new SimpleJdbcTemplate(getNamedParameterJdbcTemplate());
        return template.queryForObject(SELECT_CONTENT, CONTENT_MAPPER, params);
    } catch (EmptyResultDataAccessException erdae) {
        return null;
    }
}