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:architecture.user.dao.impl.ExternalJdbcUserDao.java

public List<User> findUsers(Company company, String nameOrEmail) {
    List<User> users = getExtendedJdbcTemplate().query(getSql("SELECT_COMPANY_USERS_BY_EMAIL_OR_NAME"),
            userMapper, new SqlParameterValue(Types.INTEGER, company.getCompanyId()),
            new SqlParameterValue(Types.VARCHAR, nameOrEmail),
            new SqlParameterValue(Types.VARCHAR, nameOrEmail));
    for (User user : users) {
        try {//from   w  w  w .  ja v a 2s . c o  m
            ((UserTemplate) user).setCompany(CompanyUtils.getCompany(user.getCompanyId()));
        } catch (CompanyNotFoundException e) {
        }
        ((UserTemplate) user).setProperties(this.getUserProperties(user.getUserId()));
    }
    return users;
}

From source file:org.waarp.common.database.data.AbstractDbData.java

/**
 * Set the values from the Json node to the current object (no database access)
 * /*from   w  ww. j a  va 2  s.  c o  m*/
 * @param node
 * @param ignorePrimaryKey
 *            True will ignore primaryKey from Json
 * @throws WaarpDatabaseSqlException
 */
public void setFromJson(ObjectNode node, boolean ignorePrimaryKey) throws WaarpDatabaseSqlException {
    DbValue[] list = allFields;
    if (ignorePrimaryKey) {
        list = otherFields;
    }
    for (DbValue value : list) {
        if (value.column.equalsIgnoreCase("UPDATEDINFO")) {
            continue;
        }
        JsonNode item = node.get(value.column);
        if (item != null && !item.isMissingNode() && !item.isNull()) {
            isSaved = false;
            switch (value.type) {
            case Types.VARCHAR:
            case Types.LONGVARCHAR:
                value.setValue(item.asText());
                break;
            case Types.BIT:
                value.setValue(item.asBoolean());
                break;
            case Types.TINYINT:
            case Types.SMALLINT:
            case Types.INTEGER:
                value.setValue(item.asInt());
                break;
            case Types.BIGINT:
                value.setValue(item.asLong());
                break;
            case Types.REAL:
            case Types.DOUBLE:
                value.setValue(item.asDouble());
                break;
            case Types.VARBINARY:
                try {
                    value.setValue(item.binaryValue());
                } catch (IOException e) {
                    throw new WaarpDatabaseSqlException("Issue while assigning array of bytes", e);
                }
                break;
            case Types.DATE:
                value.setValue(new Date(item.asLong()));
                break;
            case Types.TIMESTAMP:
                value.setValue(new Timestamp(item.asLong()));
                break;
            case Types.CLOB:
            case Types.BLOB:
            default:
                throw new WaarpDatabaseSqlException("Unsupported type: " + value.type);
            }
        }
    }
    setFromArray();
}

From source file:com.streamsets.pipeline.lib.jdbc.JdbcUtil.java

public Field resultToField(ResultSetMetaData md, ResultSet rs, int columnIndex, int maxClobSize,
        int maxBlobSize, DataType userSpecifiedType, UnknownTypeAction unknownTypeAction,
        boolean timestampToString) throws SQLException, IOException, StageException {
    Field field;/*  www .j a v  a  2s. c om*/
    if (userSpecifiedType != DataType.USE_COLUMN_TYPE) {
        // If user specifies the data type, overwrite the column type returned by database.
        field = Field.create(Field.Type.valueOf(userSpecifiedType.getLabel()), rs.getObject(columnIndex));
    } else {
        // All types as of JDBC 2.0 are here:
        // https://docs.oracle.com/javase/8/docs/api/constant-values.html#java.sql.Types.ARRAY
        // Good source of recommended mappings is here:
        // http://www.cs.mun.ca/java-api-1.5/guide/jdbc/getstart/mapping.html
        switch (md.getColumnType(columnIndex)) {
        case Types.BIGINT:
            field = Field.create(Field.Type.LONG, rs.getObject(columnIndex));
            break;
        case Types.BINARY:
        case Types.LONGVARBINARY:
        case Types.VARBINARY:
            field = Field.create(Field.Type.BYTE_ARRAY, rs.getBytes(columnIndex));
            break;
        case Types.BIT:
        case Types.BOOLEAN:
            field = Field.create(Field.Type.BOOLEAN, rs.getObject(columnIndex));
            break;
        case Types.CHAR:
        case Types.LONGNVARCHAR:
        case Types.LONGVARCHAR:
        case Types.NCHAR:
        case Types.NVARCHAR:
        case Types.VARCHAR:
            field = Field.create(Field.Type.STRING, rs.getObject(columnIndex));
            break;
        case Types.CLOB:
        case Types.NCLOB:
            field = Field.create(Field.Type.STRING, getClobString(rs.getClob(columnIndex), maxClobSize));
            break;
        case Types.BLOB:
            field = Field.create(Field.Type.BYTE_ARRAY, getBlobBytes(rs.getBlob(columnIndex), maxBlobSize));
            break;
        case Types.DATE:
            field = Field.create(Field.Type.DATE, rs.getDate(columnIndex));
            break;
        case Types.DECIMAL:
        case Types.NUMERIC:
            field = Field.create(Field.Type.DECIMAL, rs.getBigDecimal(columnIndex));
            field.setAttribute(HeaderAttributeConstants.ATTR_SCALE,
                    String.valueOf(rs.getMetaData().getScale(columnIndex)));
            field.setAttribute(HeaderAttributeConstants.ATTR_PRECISION,
                    String.valueOf(rs.getMetaData().getPrecision(columnIndex)));
            break;
        case Types.DOUBLE:
            field = Field.create(Field.Type.DOUBLE, rs.getObject(columnIndex));
            break;
        case Types.FLOAT:
        case Types.REAL:
            field = Field.create(Field.Type.FLOAT, rs.getObject(columnIndex));
            break;
        case Types.INTEGER:
            field = Field.create(Field.Type.INTEGER, rs.getObject(columnIndex));
            break;
        case Types.ROWID:
            field = Field.create(Field.Type.STRING, rs.getRowId(columnIndex).toString());
            break;
        case Types.SMALLINT:
        case Types.TINYINT:
            field = Field.create(Field.Type.SHORT, rs.getObject(columnIndex));
            break;
        case Types.TIME:
            field = Field.create(Field.Type.TIME, rs.getObject(columnIndex));
            break;
        case Types.TIMESTAMP:
            final Timestamp timestamp = rs.getTimestamp(columnIndex);
            if (timestampToString) {
                field = Field.create(Field.Type.STRING, timestamp == null ? null : timestamp.toString());
            } else {
                field = Field.create(Field.Type.DATETIME, timestamp);
                if (timestamp != null) {
                    final long actualNanos = timestamp.getNanos() % NANOS_TO_MILLIS_ADJUSTMENT;
                    if (actualNanos > 0) {
                        field.setAttribute(FIELD_ATTRIBUTE_NANOSECONDS, String.valueOf(actualNanos));
                    }
                }
            }
            break;
        // Ugly hack until we can support LocalTime, LocalDate, LocalDateTime, etc.
        case Types.TIME_WITH_TIMEZONE:
            OffsetTime offsetTime = rs.getObject(columnIndex, OffsetTime.class);
            field = Field.create(Field.Type.TIME, Date.from(offsetTime.atDate(LocalDate.MIN).toInstant()));
            break;
        case Types.TIMESTAMP_WITH_TIMEZONE:
            OffsetDateTime offsetDateTime = rs.getObject(columnIndex, OffsetDateTime.class);
            field = Field.create(Field.Type.ZONED_DATETIME, offsetDateTime.toZonedDateTime());
            break;
        //case Types.REF_CURSOR: // JDK8 only
        case Types.SQLXML:
        case Types.STRUCT:
        case Types.ARRAY:
        case Types.DATALINK:
        case Types.DISTINCT:
        case Types.JAVA_OBJECT:
        case Types.NULL:
        case Types.OTHER:
        case Types.REF:
        default:
            if (unknownTypeAction == null) {
                return null;
            }
            switch (unknownTypeAction) {
            case STOP_PIPELINE:
                throw new StageException(JdbcErrors.JDBC_37, md.getColumnType(columnIndex),
                        md.getColumnLabel(columnIndex));
            case CONVERT_TO_STRING:
                Object value = rs.getObject(columnIndex);
                if (value != null) {
                    field = Field.create(Field.Type.STRING, rs.getObject(columnIndex).toString());
                } else {
                    field = Field.create(Field.Type.STRING, null);
                }
                break;
            default:
                throw new IllegalStateException("Unknown action: " + unknownTypeAction);
            }
        }
    }

    return field;
}

From source file:ca.sqlpower.architect.ddl.LiquibaseDDLGenerator.java

private boolean isNumericType(GenericTypeDescriptor td) {
    int type = td.getDataType();
    return (type == Types.BIGINT || type == Types.INTEGER || type == Types.DECIMAL || type == Types.DOUBLE
            || type == Types.FLOAT || type == Types.NUMERIC || type == Types.REAL || type == Types.SMALLINT
            || type == Types.TINYINT);
}

From source file:edu.ncsa.sstde.indexing.postgis.PostgisIndexer.java

private int getSQLType(Object object) {
    if (object instanceof PGgeometry) {
        return Types.OTHER;
    } else if (object instanceof Timestamp) {
        return Types.TIMESTAMP;
    } else if (object instanceof String) {
        return Types.VARCHAR;
    } else if (object instanceof Double) {
        return Types.DOUBLE;
    } else if (object instanceof Float) {
        return Types.FLOAT;
    } else if (object instanceof Integer) {
        return Types.INTEGER;
    } else if (object instanceof Time) {
        return Types.TIME;
    }/*from   ww w  .  j  a  v  a 2 s .c om*/

    return Types.OTHER;
}

From source file:architecture.user.dao.impl.ExternalJdbcUserDao.java

public List<User> findUsers(Company company, String nameOrEmail, int startIndex, int numResults) {
    List<User> users = getExtendedJdbcTemplate().queryScrollable(
            getSql("SELECT_COMPANY_USERS_BY_EMAIL_OR_NAME"), startIndex, numResults,
            new Object[] { company.getCompanyId(), nameOrEmail, nameOrEmail },
            new int[] { Types.INTEGER, Types.VARCHAR, Types.VARCHAR }, userMapper);
    for (User user : users) {
        try {//from  w w w .j ava 2 s. c o m
            ((UserTemplate) user).setCompany(CompanyUtils.getCompany(user.getCompanyId()));
        } catch (CompanyNotFoundException e) {
        }
        ((UserTemplate) user).setProperties(this.getUserProperties(user.getUserId()));
    }
    return users;
}

From source file:cn.gov.scciq.timer.acceptOrder.FRMDao.java

/**
 * ?:?/*w w  w . j a v a2 s  .c  om*/
 * @return
 */
public static int checkRapidRelease(String declNo) {
    int retCode = -1;
    Connection conn = null;
    CallableStatement proc = null;
    ResultSet rs = null;
    String call = "{call Pro_CheckRapidRelease(?,?)}";
    try {
        conn = DBPool.ds.getConnection();
        proc = conn.prepareCall(call);
        proc.setString(1, declNo);
        proc.registerOutParameter(2, Types.INTEGER);
        proc.execute();
        retCode = proc.getInt(2);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        log.error("N60", e);
    } catch (Exception e) {
        log.error("N61", e);
    } finally {
        try {
            if (rs != null) {
                rs.close();
            }
            if (proc != null) {
                proc.close();
            }
            if (conn != null) {
                conn.close();
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            log.error("N62", e);
        }
    }
    return retCode;
}

From source file:com.alibaba.wasp.jdbc.TestPreparedStatement.java

public void testDataTypes() throws SQLException {
    conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
    conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
    Statement stat = conn.createStatement();
    PreparedStatement prep;//from   ww w .  j  a  va  2  s .c  o m
    ResultSet rs;
    trace("Create tables");
    stat.execute("CREATE TABLE T_INT(ID INT PRIMARY KEY,VALUE INT)");
    stat.execute("CREATE TABLE T_VARCHAR(ID INT PRIMARY KEY,VALUE VARCHAR(255))");
    stat.execute("CREATE TABLE T_DECIMAL_0(ID INT PRIMARY KEY,VALUE DECIMAL(30,0))");
    stat.execute("CREATE TABLE T_DECIMAL_10(ID INT PRIMARY KEY,VALUE DECIMAL(20,10))");
    stat.execute("CREATE TABLE T_DATETIME(ID INT PRIMARY KEY,VALUE DATETIME)");
    prep = conn.prepareStatement("INSERT INTO T_INT VALUES(?,?)", ResultSet.TYPE_FORWARD_ONLY,
            ResultSet.CONCUR_READ_ONLY);
    prep.setInt(1, 1);
    prep.setInt(2, 0);
    prep.executeUpdate();
    prep.setInt(1, 2);
    prep.setInt(2, -1);
    prep.executeUpdate();
    prep.setInt(1, 3);
    prep.setInt(2, 3);
    prep.executeUpdate();
    prep.setInt(1, 4);
    prep.setNull(2, Types.INTEGER);
    prep.executeUpdate();
    prep.setInt(1, 5);
    prep.setBigDecimal(2, new BigDecimal("0"));
    prep.executeUpdate();
    prep.setInt(1, 6);
    prep.setString(2, "-1");
    prep.executeUpdate();
    prep.setInt(1, 7);
    prep.setObject(2, new Integer(3));
    prep.executeUpdate();
    prep.setObject(1, "8");
    // should throw an exception
    prep.setObject(2, null);
    // some databases don't allow calling setObject with null (no data type)
    prep.executeUpdate();
    prep.setInt(1, 9);
    prep.setObject(2, -4, Types.VARCHAR);
    prep.executeUpdate();
    prep.setInt(1, 10);
    prep.setObject(2, "5", Types.INTEGER);
    prep.executeUpdate();
    prep.setInt(1, 11);
    prep.setObject(2, null, Types.INTEGER);
    prep.executeUpdate();
    prep.setInt(1, 12);
    prep.setBoolean(2, true);
    prep.executeUpdate();
    prep.setInt(1, 13);
    prep.setBoolean(2, false);
    prep.executeUpdate();
    prep.setInt(1, 14);
    prep.setByte(2, (byte) -20);
    prep.executeUpdate();
    prep.setInt(1, 15);
    prep.setByte(2, (byte) 100);
    prep.executeUpdate();
    prep.setInt(1, 16);
    prep.setShort(2, (short) 30000);
    prep.executeUpdate();
    prep.setInt(1, 17);
    prep.setShort(2, (short) (-30000));
    prep.executeUpdate();
    prep.setInt(1, 18);
    prep.setLong(2, Integer.MAX_VALUE);
    prep.executeUpdate();
    prep.setInt(1, 19);
    prep.setLong(2, Integer.MIN_VALUE);
    prep.executeUpdate();

    assertTrue(stat.execute("SELECT * FROM T_INT ORDER BY ID"));
    rs = stat.getResultSet();
    assertResultSetOrdered(rs,
            new String[][] { { "1", "0" }, { "2", "-1" }, { "3", "3" }, { "4", null }, { "5", "0" },
                    { "6", "-1" }, { "7", "3" }, { "8", null }, { "9", "-4" }, { "10", "5" }, { "11", null },
                    { "12", "1" }, { "13", "0" }, { "14", "-20" }, { "15", "100" }, { "16", "30000" },
                    { "17", "-30000" }, { "18", "" + Integer.MAX_VALUE }, { "19", "" + Integer.MIN_VALUE }, });

    prep = conn.prepareStatement("INSERT INTO T_DECIMAL_0 VALUES(?,?)");
    prep.setInt(1, 1);
    prep.setLong(2, Long.MAX_VALUE);
    prep.executeUpdate();
    prep.setInt(1, 2);
    prep.setLong(2, Long.MIN_VALUE);
    prep.executeUpdate();
    prep.setInt(1, 3);
    prep.setFloat(2, 10);
    prep.executeUpdate();
    prep.setInt(1, 4);
    prep.setFloat(2, -20);
    prep.executeUpdate();
    prep.setInt(1, 5);
    prep.setFloat(2, 30);
    prep.executeUpdate();
    prep.setInt(1, 6);
    prep.setFloat(2, -40);
    prep.executeUpdate();

    rs = stat.executeQuery("SELECT VALUE FROM T_DECIMAL_0 ORDER BY ID");
    checkBigDecimal(rs, new String[] { "" + Long.MAX_VALUE, "" + Long.MIN_VALUE, "10", "-20", "30", "-40" });
}

From source file:com.splicemachine.db.impl.sql.compile.QueryTreeNode.java

/**
 * Get a ConstantNode to represent a typed null value.
 *
 * @param type Type of the null node./* w ww .j av  a  2s .c  o m*/
 * @throws StandardException Thrown on error
 * @return A ConstantNode with the specified type, and a value of null
 */
public ConstantNode getNullNode(DataTypeDescriptor type) throws StandardException {
    int constantNodeType;
    switch (type.getTypeId().getJDBCTypeId()) {
    case Types.VARCHAR:
        constantNodeType = C_NodeTypes.VARCHAR_CONSTANT_NODE;
        break;
    case Types.CHAR:
        constantNodeType = C_NodeTypes.CHAR_CONSTANT_NODE;
        break;
    case Types.TINYINT:
        constantNodeType = C_NodeTypes.TINYINT_CONSTANT_NODE;
        break;
    case Types.SMALLINT:
        constantNodeType = C_NodeTypes.SMALLINT_CONSTANT_NODE;
        break;
    case Types.INTEGER:
        constantNodeType = C_NodeTypes.INT_CONSTANT_NODE;
        break;
    case Types.BIGINT:
        constantNodeType = C_NodeTypes.LONGINT_CONSTANT_NODE;
        break;
    case Types.REAL:
        constantNodeType = C_NodeTypes.FLOAT_CONSTANT_NODE;
        break;
    case Types.DOUBLE:
        constantNodeType = C_NodeTypes.DOUBLE_CONSTANT_NODE;
        break;
    case Types.NUMERIC:
    case Types.DECIMAL:
        constantNodeType = C_NodeTypes.DECIMAL_CONSTANT_NODE;
        break;
    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
        constantNodeType = C_NodeTypes.USERTYPE_CONSTANT_NODE;
        break;
    case Types.BINARY:
        constantNodeType = C_NodeTypes.BIT_CONSTANT_NODE;
        break;
    case Types.VARBINARY:
        constantNodeType = C_NodeTypes.VARBIT_CONSTANT_NODE;
        break;
    case Types.LONGVARCHAR:
        constantNodeType = C_NodeTypes.LONGVARCHAR_CONSTANT_NODE;
        break;
    case Types.CLOB:
        constantNodeType = C_NodeTypes.CLOB_CONSTANT_NODE;
        break;
    case Types.LONGVARBINARY:
        constantNodeType = C_NodeTypes.LONGVARBIT_CONSTANT_NODE;
        break;
    case Types.BLOB:
        constantNodeType = C_NodeTypes.BLOB_CONSTANT_NODE;
        break;
    case JDBC40Translation.SQLXML:
        constantNodeType = C_NodeTypes.XML_CONSTANT_NODE;
        break;
    case Types.BOOLEAN:
        constantNodeType = C_NodeTypes.BOOLEAN_CONSTANT_NODE;
        break;
    default:
        if (type.getTypeId().userType()) {
            constantNodeType = C_NodeTypes.USERTYPE_CONSTANT_NODE;
        } else {
            throw StandardException.newException(SQLState.LANG_NONULL_DATATYPE,
                    type.getTypeId().getSQLTypeName());
        }
    }

    ConstantNode constantNode = (ConstantNode) getNodeFactory().getNode(constantNodeType, type.getTypeId(), cm);

    constantNode.setType(type.getNullabilityType(true));

    return constantNode;
}

From source file:architecture.user.dao.impl.ExternalJdbcUserDao.java

public int getFoundUserCount(Company company, String nameOrEmail) {
    return getExtendedJdbcTemplate().queryForInt(getSql("COUNT_COMPANY_USERS_BY_EMAIL_OR_NAME"),
            new SqlParameterValue(Types.INTEGER, company.getCompanyId()),
            new SqlParameterValue(Types.VARCHAR, nameOrEmail),
            new SqlParameterValue(Types.VARCHAR, nameOrEmail));
}