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:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSybase.CFAsteriskSybaseClusterTable.java

public int nextSecGroupIdGen(CFSecurityAuthorization Authorization, CFSecurityClusterPKey PKey) {
    final String S_ProcName = "nextSecGroupIdGen";
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Not in a transaction");
    }/* w ww . j a  v  a  2s .co  m*/
    Connection cnx = schema.getCnx();
    long Id = PKey.getRequiredId();

    CallableStatement stmtSelectNextSecGroupIdGen = null;
    try {
        String sql = "{ call sp_next_secgroupidgen( ?" + ", " + "?" + " ) }";
        stmtSelectNextSecGroupIdGen = cnx.prepareCall(sql);
        int argIdx = 1;
        stmtSelectNextSecGroupIdGen.registerOutParameter(argIdx++, java.sql.Types.INTEGER);
        stmtSelectNextSecGroupIdGen.setLong(argIdx++, Id);
        stmtSelectNextSecGroupIdGen.execute();
        int nextId = stmtSelectNextSecGroupIdGen.getInt(1);
        return (nextId);
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    } finally {
        if (stmtSelectNextSecGroupIdGen != null) {
            try {
                stmtSelectNextSecGroupIdGen.close();
            } catch (SQLException e) {
            }
            stmtSelectNextSecGroupIdGen = null;
        }
    }
}

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 a2s.  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:konditer.client.dao.ContactDao.java

@Override
public int deleteContact(int contactId) {
    String SQL_QUERY = "DELETE FROM contacts WHERE CONTACT_ID = ?";
    int rowCount = jdbcTemplate.update(SQL_QUERY, new Object[] { contactId }, new int[] { Types.INTEGER });
    Logger.getLogger(ContactDao.class.getName()).log(Level.SEVERE,
            " : {0} .", rowCount);
    return rowCount;
}

From source file:com.act.lcms.db.model.InductionWell.java

protected void bindInsertOrUpdateParameters(PreparedStatement stmt, Integer plateId, Integer plateRow,
        Integer plateColumn, String msid, String chemicalSource, String composition, String chemical,
        String strainSource, String note, Integer growth) throws SQLException {
    stmt.setInt(DB_FIELD.PLATE_ID.getInsertUpdateOffset(), plateId);
    stmt.setInt(DB_FIELD.PLATE_ROW.getInsertUpdateOffset(), plateRow);
    stmt.setInt(DB_FIELD.PLATE_COLUMN.getInsertUpdateOffset(), plateColumn);
    stmt.setString(DB_FIELD.MSID.getInsertUpdateOffset(), msid);
    stmt.setString(DB_FIELD.CHEMICAL_SOURCE.getInsertUpdateOffset(), chemicalSource);
    stmt.setString(DB_FIELD.COMPOSITION.getInsertUpdateOffset(), composition);
    stmt.setString(DB_FIELD.CHEMICAL.getInsertUpdateOffset(), chemical);
    stmt.setString(DB_FIELD.STRAIN_SOURCE.getInsertUpdateOffset(), strainSource);
    stmt.setString(DB_FIELD.NOTE.getInsertUpdateOffset(), note);
    if (growth == null) {
        stmt.setNull(DB_FIELD.GROWTH.getInsertUpdateOffset(), Types.INTEGER);
    } else {/*from  w ww  .  j av  a  2 s .  c  om*/
        stmt.setInt(DB_FIELD.GROWTH.getInsertUpdateOffset(), growth);
    }
}

From source file:ca.sqlpower.architect.swingui.TestPlayPen.java

/**
 * Test to ensure that the self-referencing table gets imported properly into the PlayPen.
 * @throws Exception//from  w w w . j  a v a2  s .  co  m
 */
public void testImportTableCopyOnSelfReferencingTable() throws Exception {
    SQLDatabase sourceDB = new SQLDatabase();
    pp.getSession().getRootObject().addChild(sourceDB);
    SQLTable table = new SQLTable(sourceDB, true);
    table.setName("self_ref");
    SQLColumn pkCol = new SQLColumn(table, "key", Types.INTEGER, 10, 0);
    table.addColumn(pkCol);
    table.addToPK(table.getColumn(0));
    SQLColumn fkCol = new SQLColumn(table, "self_ref_column", Types.INTEGER, 10, 0);
    table.addColumn(fkCol);

    SQLRelationship rel = new SQLRelationship();
    rel.attachRelationship(table, table, false);
    rel.addMapping(pkCol, fkCol);
    sourceDB.addChild(table);

    pp.importTableCopy(table, new Point(10, 10), ASUtils.createDuplicateProperties(pp.getSession(), table));

    int relCount = 0;
    int tabCount = 0;
    int otherCount = 0;
    for (PlayPenComponent ppc : pp.getContentPane().getChildren()) {
        if (ppc instanceof Relationship) {
            relCount++;
        } else if (ppc instanceof TablePane) {
            tabCount++;
        } else {
            otherCount++;
        }
    }
    assertEquals("Expected one table in pp", 1, tabCount);
    assertEquals("Expected one relationship in pp", 1, relCount);
    assertEquals("Found junk in playpen", 0, otherCount);
}

From source file:CreateNewType.java

private static Vector getDataTypes(Connection con, String typeToCreate) throws SQLException {
    String structName = null, distinctName = null, javaName = null;

    // create a vector of class DataType initialized with
    // the SQL code, the SQL type name, and two null entries
    // for the local type name and the creation parameter(s)

    Vector dataTypes = new Vector();
    dataTypes.add(new DataType(java.sql.Types.BIT, "BIT"));
    dataTypes.add(new DataType(java.sql.Types.TINYINT, "TINYINT"));
    dataTypes.add(new DataType(java.sql.Types.SMALLINT, "SMALLINT"));
    dataTypes.add(new DataType(java.sql.Types.INTEGER, "INTEGER"));
    dataTypes.add(new DataType(java.sql.Types.BIGINT, "BIGINT"));
    dataTypes.add(new DataType(java.sql.Types.FLOAT, "FLOAT"));
    dataTypes.add(new DataType(java.sql.Types.REAL, "REAL"));
    dataTypes.add(new DataType(java.sql.Types.DOUBLE, "DOUBLE"));
    dataTypes.add(new DataType(java.sql.Types.NUMERIC, "NUMERIC"));
    dataTypes.add(new DataType(java.sql.Types.DECIMAL, "DECIMAL"));
    dataTypes.add(new DataType(java.sql.Types.CHAR, "CHAR"));
    dataTypes.add(new DataType(java.sql.Types.VARCHAR, "VARCHAR"));
    dataTypes.add(new DataType(java.sql.Types.LONGVARCHAR, "LONGVARCHAR"));
    dataTypes.add(new DataType(java.sql.Types.DATE, "DATE"));
    dataTypes.add(new DataType(java.sql.Types.TIME, "TIME"));
    dataTypes.add(new DataType(java.sql.Types.TIMESTAMP, "TIMESTAMP"));
    dataTypes.add(new DataType(java.sql.Types.BINARY, "BINARY"));
    dataTypes.add(new DataType(java.sql.Types.VARBINARY, "VARBINARY"));
    dataTypes.add(new DataType(java.sql.Types.LONGVARBINARY, "LONGVARBINARY"));
    dataTypes.add(new DataType(java.sql.Types.NULL, "NULL"));
    dataTypes.add(new DataType(java.sql.Types.OTHER, "OTHER"));
    dataTypes.add(new DataType(java.sql.Types.BLOB, "BLOB"));
    dataTypes.add(new DataType(java.sql.Types.CLOB, "CLOB"));

    DatabaseMetaData dbmd = con.getMetaData();
    ResultSet rs = dbmd.getTypeInfo();
    while (rs.next()) {
        int codeNumber = rs.getInt("DATA_TYPE");
        String dbmsName = rs.getString("TYPE_NAME");
        String createParams = rs.getString("CREATE_PARAMS");

        if (codeNumber == Types.STRUCT && structName == null)
            structName = dbmsName;// www.j av a  2s  .  c  o m
        else if (codeNumber == Types.DISTINCT && distinctName == null)
            distinctName = dbmsName;
        else if (codeNumber == Types.JAVA_OBJECT && javaName == null)
            javaName = dbmsName;
        else {
            for (int i = 0; i < dataTypes.size(); i++) {
                // find entry that matches the SQL code, 
                // and if local type and params are not already set,
                // set them
                DataType type = (DataType) dataTypes.get(i);
                if (type.getCode() == codeNumber) {
                    type.setLocalTypeAndParams(dbmsName, createParams);
                }
            }
        }
    }

    if (typeToCreate.equals("s")) {
        int[] types = { Types.STRUCT, Types.DISTINCT, Types.JAVA_OBJECT };
        rs = dbmd.getUDTs(null, "%", "%", types);
        while (rs.next()) {
            String typeName = null;
            DataType dataType = null;

            if (dbmd.isCatalogAtStart())
                typeName = rs.getString(1) + dbmd.getCatalogSeparator() + rs.getString(2) + "."
                        + rs.getString(3);
            else
                typeName = rs.getString(2) + "." + rs.getString(3) + dbmd.getCatalogSeparator()
                        + rs.getString(1);

            switch (rs.getInt(5)) {
            case Types.STRUCT:
                dataType = new DataType(Types.STRUCT, typeName);
                dataType.setLocalTypeAndParams(structName, null);
                break;
            case Types.DISTINCT:
                dataType = new DataType(Types.DISTINCT, typeName);
                dataType.setLocalTypeAndParams(distinctName, null);
                break;
            case Types.JAVA_OBJECT:
                dataType = new DataType(Types.JAVA_OBJECT, typeName);
                dataType.setLocalTypeAndParams(javaName, null);
                break;
            }
            dataTypes.add(dataType);
        }
    }

    return dataTypes;
}

From source file:com.flexive.ejb.beans.structure.TypeEngineBean.java

/**
 * Create a new type/*from  w  w w .j a  v  a2s. c  o m*/
 *
 * @param type the type to create
 * @return id of the new type
 * @throws FxApplicationException on errors
 */
private long create(FxTypeEdit type) throws FxApplicationException {
    final UserTicket ticket = FxContext.getUserTicket();
    FxPermissionUtils.checkRole(ticket, Role.StructureManagement);
    final FxEnvironment environment = CacheAdmin.getEnvironment();
    if (StringUtils.isEmpty(type.getName()))
        throw new FxInvalidParameterException("NAME", "ex.structure.create.nameMissing");
    if (!type.getStorageMode().isSupported())
        throw new FxInvalidParameterException("STORAGEMODE", "ex.structure.typeStorageMode.notSupported",
                type.getStorageMode().getLabel().getBestTranslation(ticket));
    if (type.getACL().getCategory() != ACLCategory.STRUCTURE)
        throw new FxInvalidParameterException("aclId", "ex.acl.category.invalid",
                type.getACL().getCategory().name(), ACLCategory.STRUCTURE.name());
    if (type.hasDefaultInstanceACL() && type.getDefaultInstanceACL().getCategory() != ACLCategory.INSTANCE)
        throw new FxInvalidParameterException("DEFACL", "ex.acl.category.invalid",
                type.getDefaultInstanceACL().getCategory(), ACLCategory.INSTANCE);
    Connection con = null;
    PreparedStatement ps = null;
    long newId = seq.getId(FxSystemSequencer.TYPEDEF);
    final long NOW = System.currentTimeMillis();
    try {
        con = Database.getDbConnection();
        ps = con.prepareStatement(TYPE_CREATE);
        ps.setLong(1, newId);
        ps.setString(2, type.getName());
        if (type.getParent() != null)
            ps.setLong(3, type.getParent().getId());
        else
            ps.setNull(3, java.sql.Types.INTEGER);
        ps.setInt(4, type.getStorageMode().getId());
        ps.setInt(5, type.getCategory().getId());
        ps.setInt(6, type.getMode().getId());
        ps.setInt(7, type.getLanguage().getId());
        ps.setInt(8, type.getState().getId());
        ps.setByte(9, type.getBitCodedPermissions());
        ps.setBoolean(10, type.isTrackHistory());
        ps.setLong(11, type.getHistoryAge());
        ps.setLong(12, type.getMaxVersions());
        ps.setInt(13, type.getMaxRelSource());
        ps.setInt(14, type.getMaxRelDestination());
        ps.setLong(15, ticket.getUserId());
        ps.setLong(16, NOW);
        ps.setLong(17, ticket.getUserId());
        ps.setLong(18, NOW);
        ps.setLong(19, type.getACL().getId());
        ps.setLong(20, type.getWorkflow().getId());
        if (type.getIcon().isEmpty())
            ps.setNull(21, java.sql.Types.INTEGER);
        else
            ps.setLong(21, type.getIcon().getDefaultTranslation().getId());
        ps.setBoolean(22, type.isUseInstancePermissions() && type.isMultipleContentACLs());
        ps.setBoolean(23, type.isIncludedInSupertypeQueries());
        if (type.hasDefaultInstanceACL())
            ps.setLong(24, type.getDefaultInstanceACL().getId());
        else
            ps.setNull(24, java.sql.Types.INTEGER);
        ps.setBoolean(25, type.isAutoVersion());
        ps.executeUpdate();
        Database.storeFxString(type.getLabel(), con, TBL_STRUCT_TYPES, "DESCRIPTION", "ID", newId);

        StructureLoader.reload(con);
        FxType thisType = CacheAdmin.getEnvironment().getType(newId);
        htracker.track(thisType, "history.type.create", type.getName(), newId);

        //store relations
        ps.close();
        if (type.getAddedRelations().size() > 0) {
            ps = con.prepareStatement("INSERT INTO " + TBL_STRUCT_TYPERELATIONS
                    + " (TYPEDEF,TYPESRC,TYPEDST,MAXSRC,MAXDST)VALUES(?,?,?,?,?)");
            ps.setLong(1, thisType.getId());
            for (FxTypeRelation rel : type.getAddedRelations()) {
                if (rel.getSource().isRelation())
                    throw new FxInvalidParameterException("ex.structure.type.relation.wrongTarget",
                            type.getName(), rel.getSource().getName());
                if (rel.getDestination().isRelation())
                    throw new FxInvalidParameterException("ex.structure.type.relation.wrongTarget",
                            type.getName(), rel.getDestination().getName());
                ps.setLong(2, rel.getSource().getId());
                ps.setLong(3, rel.getDestination().getId());
                ps.setLong(4, rel.getMaxSource());
                ps.setLong(5, rel.getMaxDestination());
                ps.addBatch();
                htracker.track(thisType, "history.type.create.relation.add", type.getName(),
                        rel.getSource().getName(), rel.getMaxSource(), rel.getDestination().getName(),
                        rel.getMaxDestination());
            }
            ps.executeBatch();
        }

        if (type.getParent() == null) {
            for (FxPropertyAssignment spa : environment.getSystemInternalRootPropertyAssignments()) {
                final FxPropertyAssignmentEdit derived = FxPropertyAssignmentEdit.createNew(spa, thisType,
                        spa.getAlias(), "/");
                assignmentEngine.save(
                        updateAclAssignmentMultiplicity(type, derived).setEnabled(true)._setSystemInternal(),
                        false);
            }
        } else {
            //create parent assignments
            List<FxAssignment> parentAssignments = type.getParent().getConnectedAssignments("/");
            for (FxAssignment as : parentAssignments) {
                if (as instanceof FxPropertyAssignment) {
                    FxPropertyAssignmentEdit pae = FxPropertyAssignmentEdit.createNew((FxPropertyAssignment) as,
                            thisType, as.getAlias(), "/");
                    pae.setEnabled(type.isEnableParentAssignments());
                    assignmentEngine.save(updateAclAssignmentMultiplicity(type, pae), false);
                } else if (as instanceof FxGroupAssignment) {
                    FxGroupAssignmentEdit pge = FxGroupAssignmentEdit.createNew((FxGroupAssignment) as,
                            thisType, as.getAlias(), "/");
                    pge.setEnabled(type.isEnableParentAssignments());
                    assignmentEngine.save(pge, true);
                }
            }
        }

        // store structure options
        storeTypeOptions(con, TBL_STRUCT_TYPES_OPTIONS, "ID", newId, type.getOptions(), false);

        StructureLoader.reload(con);
    } catch (SQLException e) {
        if (StorageManager.isUniqueConstraintViolation(e)) {
            EJBUtils.rollback(ctx);
            throw new FxCreateException("ex.structure.type.exists", type.getName());
        }
        EJBUtils.rollback(ctx);
        throw new FxCreateException(LOG, e, "ex.db.sqlError", e.getMessage());
    } catch (FxCacheException e) {
        EJBUtils.rollback(ctx);
        throw new FxCreateException(LOG, e, "ex.cache", e.getMessage());
    } catch (FxLoadException e) {
        EJBUtils.rollback(ctx);
        throw new FxCreateException(e);
    } catch (FxNotFoundException e) {
        EJBUtils.rollback(ctx);
        throw new FxCreateException(e);
    } catch (FxEntryExistsException e) {
        EJBUtils.rollback(ctx);
        throw new FxCreateException(e);
    } catch (FxUpdateException e) {
        EJBUtils.rollback(ctx);
        throw new FxCreateException(e);
    } finally {
        Database.closeObjects(TypeEngineBean.class, con, ps);
    }
    return newId;
}

From source file:com.act.lcms.db.model.ChemicalAssociatedWithPathway.java

protected void bindInsertOrUpdateParameters(PreparedStatement stmt, String constructId, String chemical,
        String kind, Integer index) throws SQLException {
    stmt.setString(DB_FIELD.CONSTRUCT_ID.getInsertUpdateOffset(), constructId);
    stmt.setString(DB_FIELD.CHEMICAL.getInsertUpdateOffset(), chemical);
    stmt.setString(DB_FIELD.KIND.getInsertUpdateOffset(), kind);
    if (index != null) {
        stmt.setInt(DB_FIELD.INDEX.getInsertUpdateOffset(), index);
    } else {/*  www  .j av a2s  . com*/
        stmt.setNull(DB_FIELD.INDEX.getInsertUpdateOffset(), Types.INTEGER);
    }
}

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

public int saveConversation(int requestId, int responseId) throws DataAccessException {
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue(REQUESTID, requestId, Types.INTEGER);
    params.addValue(RESPONSEID, responseId, Types.INTEGER);

    KeyHolder key = new GeneratedKeyHolder();
    getNamedParameterJdbcTemplate().update(INSERT_CONVERSATION, params, key);
    return key.getKey().intValue();
}

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

public void testMegaConstructor() throws Exception {
    SQLColumn col = new SQLColumn(table0pk, "test_column_2", Types.INTEGER, "my_test_integer", 44, 33,
            DatabaseMetaData.columnNullable, "test remarks", "test default", true);
    assertEquals(table0pk, col.getParent());
    assertEquals("test_column_2", col.getName());
    assertEquals(Types.INTEGER, col.getType());
    assertEquals("my_test_integer", col.getSourceDataTypeName());
    assertEquals(44, col.getPrecision());
    assertEquals(33, col.getScale());//from   w  w w.j  a  va 2  s .co  m
    assertEquals(DatabaseMetaData.columnNullable, col.getNullable());
    assertEquals("test remarks", col.getRemarks());
    assertEquals("test default", col.getDefaultValue());
    assertTrue(col.isAutoIncrement());
    assertEquals(1, col.getReferenceCount());
    assertEquals(1, col.getChildCount());
}