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:com.mobiaware.auction.data.impl.MySqlDataServiceImpl.java

@Override
public int editCategory(final Category category) {
    int uid = -1;

    Connection conn = null;//from w w w. ja  va 2s  .  c  o  m
    CallableStatement stmt = null;

    try {
        conn = _dataSource.getConnection();

        stmt = conn.prepareCall("{call SP_EDITCATEGORY (?,?,?)}");
        stmt.registerOutParameter(1, Types.INTEGER);
        stmt.setInt(2, category.getAuctionUid());
        stmt.setString(3, category.getName());

        stmt.execute();

        uid = stmt.getInt(1);
    } catch (SQLException e) {
        LOG.error(Throwables.getStackTraceAsString(e));

        uid = -1;
    } finally {
        DbUtils.closeQuietly(conn, stmt, null);
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("CATEGORY [method:{} result:{}]", new Object[] { "edit", uid });
    }

    return uid;
}

From source file:com.webpagebytes.wpbsample.database.WPBDatabase.java

public DepositWithdrawal createDepositOrWithdrawal(int user_id, DepositWithdrawal.OperationType type,
        long amount) throws SQLException {
    Connection connection = getConnection();
    PreparedStatement statement = null;
    PreparedStatement statementAccount = null;

    DepositWithdrawal operation = new DepositWithdrawal();
    try {// www .  j av  a2s.  c o  m
        statement = connection.prepareStatement(CREATE_ACCOUNTOPERATIONS_STATEMENT);
        connection.setAutoCommit(false);

        statement.setInt(1, user_id);
        int typeOperation = ACCOUNT_OPERATION_DEPOSIT;
        if (type == OperationType.WITHDRAWAL) {
            typeOperation = ACCOUNT_OPERATION_WITHDRAWAL;
        }
        statement.setInt(2, typeOperation);

        statement.setLong(3, amount);
        Date now = new Date();
        java.sql.Timestamp sqlDate = new java.sql.Timestamp(now.getTime());
        statement.setTimestamp(4, sqlDate);
        statement.setNull(5, Types.INTEGER);
        statement.setNull(6, Types.INTEGER);

        statement.execute();
        ResultSet rs = statement.getGeneratedKeys();
        if (rs.next()) {
            operation.setId(rs.getInt(1));
            operation.setAmount(amount);
            operation.setDate(now);
            operation.setType(type);
        }
        Account account = getAccount(user_id);
        long balanceToSet = 0L;
        if (type == OperationType.DEPOSIT) {
            balanceToSet = account.getBalance() + amount;
        } else {
            balanceToSet = account.getBalance() - amount;
        }
        if (balanceToSet < 0) {
            throw new SQLException("Balance cannot become negative");
        }
        statementAccount = connection.prepareStatement(UPDATE_ACCOUNT_BY_ID_STATEMENT);
        statementAccount.setLong(1, balanceToSet);
        statementAccount.setInt(2, user_id);
        statementAccount.execute();

        connection.commit();
    } catch (SQLException e) {
        if (connection != null) {
            connection.rollback();
        }
        throw e;
    } finally {
        if (statement != null) {
            statement.close();
        }
        if (connection != null) {
            connection.close();
        }
    }
    return operation;
}

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

public User getUserById(long userId) {

    if (userId <= 0L) {
        return null;
    }/*from  w w  w. java  2  s. c om*/

    UserTemplate user = null;
    try {
        user = (UserTemplate) getExtendedJdbcTemplate().queryForObject(getSql("SELECT_USER_BY_ID"),
                getExternalUserRowMapper(), new SqlParameterValue(Types.INTEGER, userId));
        user.setProfile(getUserProfile(user.getUserId()));
        user.setProperties(getUserProperties(user.getUserId()));
    } catch (IncorrectResultSizeDataAccessException e) {
        if (e.getActualSize() > 1) {
            log.warn((new StringBuilder()).append("Multiple occurrances of the same user ID found: ")
                    .append(userId).toString());
            throw e;
        }
    } catch (DataAccessException e) {
        String message = (new StringBuilder()).append("Failure attempting to load user by ID : ").append(userId)
                .append(".").toString();
        log.fatal(message, e);
    }
    return user;

}

From source file:jongo.jdbc.JDBCExecutor.java

/**
 * Utility method which registers in a CallableStatement object the different {@link jongo.jdbc.StoredProcedureParam}
 * instances in the given list. Returns a List of {@link jongo.jdbc.StoredProcedureParam} with all the OUT parameters
 * registered in the CallableStatement//  www. j a v  a  2s.  c  o m
 * @param cs the CallableStatement object where the parameters are registered.
 * @param params a list of {@link jongo.jdbc.StoredProcedureParam}
 * @return a list of OUT {@link jongo.jdbc.StoredProcedureParam} 
 * @throws SQLException if we fail to register any of the parameters in the CallableStatement
 */
private static List<StoredProcedureParam> addParameters(final CallableStatement cs,
        final List<StoredProcedureParam> params) throws SQLException {
    List<StoredProcedureParam> outParams = new ArrayList<StoredProcedureParam>();
    int i = 1;
    for (StoredProcedureParam p : params) {
        final Integer sqlType = p.getType();
        if (p.isOutParameter()) {
            l.debug("Adding OUT parameter " + p.toString());
            cs.registerOutParameter(i++, sqlType);
            outParams.add(p);
        } else {
            l.debug("Adding IN parameter " + p.toString());
            switch (sqlType) {
            case Types.BIGINT:
            case Types.INTEGER:
            case Types.TINYINT:
                //                    case Types.NUMERIC:
                cs.setInt(i++, Integer.valueOf(p.getValue()));
                break;
            case Types.DATE:
                cs.setDate(i++, (Date) JongoUtils.parseValue(p.getValue()));
                break;
            case Types.TIME:
                cs.setTime(i++, (Time) JongoUtils.parseValue(p.getValue()));
                break;
            case Types.TIMESTAMP:
                cs.setTimestamp(i++, (Timestamp) JongoUtils.parseValue(p.getValue()));
                break;
            case Types.DECIMAL:
                cs.setBigDecimal(i++, (BigDecimal) JongoUtils.parseValue(p.getValue()));
                break;
            case Types.DOUBLE:
                cs.setDouble(i++, Double.valueOf(p.getValue()));
                break;
            case Types.FLOAT:
                cs.setLong(i++, Long.valueOf(p.getValue()));
                break;
            default:
                cs.setString(i++, p.getValue());
                break;
            }
        }
    }
    return outParams;
}

From source file:com.mapd.utility.SQLImporter.java

private String getColType(int cType, int precision, int scale) {
    if (precision > 19) {
        precision = 19;// www  . j  a v a 2  s.co m
    }
    if (scale > 19) {
        scale = 18;
    }
    switch (cType) {
    case java.sql.Types.TINYINT:
    case java.sql.Types.SMALLINT:
        return ("SMALLINT");
    case java.sql.Types.INTEGER:
        return ("INTEGER");
    case java.sql.Types.BIGINT:
        return ("BIGINT");
    case java.sql.Types.FLOAT:
        return ("FLOAT");
    case java.sql.Types.DECIMAL:
        return ("DECIMAL(" + precision + "," + scale + ")");
    case java.sql.Types.DOUBLE:
        return ("DOUBLE");
    case java.sql.Types.REAL:
        return ("REAL");
    case java.sql.Types.NUMERIC:
        return ("NUMERIC(" + precision + "," + scale + ")");
    case java.sql.Types.TIME:
        return ("TIME");
    case java.sql.Types.TIMESTAMP:
        return ("TIMESTAMP");
    case java.sql.Types.DATE:
        return ("DATE");
    case java.sql.Types.BOOLEAN:
    case java.sql.Types.BIT: // deal with postgress treating boolean as bit... this will bite me
        return ("BOOLEAN");
    case java.sql.Types.NVARCHAR:
    case java.sql.Types.VARCHAR:
    case java.sql.Types.NCHAR:
    case java.sql.Types.CHAR:
    case java.sql.Types.LONGVARCHAR:
    case java.sql.Types.LONGNVARCHAR:
        return ("TEXT ENCODING DICT");
    default:
        throw new AssertionError("Column type " + cType + " not Supported");
    }
}

From source file:com.wso2telco.dep.operatorservice.dao.OperatorDAO.java

public void insertBlacklistAggregatoRows(final Integer appID, final String subscriber, final int operatorid,
        final String[] merchants) throws SQLException, Exception {

    Connection con = null;// w  w w  .  j  a v a 2 s  .c om
    final StringBuilder sql = new StringBuilder();
    PreparedStatement pst = null;

    try {

        con = DbUtils.getDbConnection(DataSourceNames.WSO2TELCO_DEP_DB);

        sql.append(" INSERT INTO ");
        sql.append(OparatorTable.MERCHANT_OPCO_BLACKLIST.getTObject());
        sql.append(" (application_id, operator_id, subscriber, merchant)");
        sql.append("VALUES (?, ?, ?, ?) ");

        pst = con.prepareStatement(sql.toString());

        /**
         * Set autocommit off to handle the transaction
         */
        con.setAutoCommit(false);

        /**
         * each merchant log as black listed
         */
        for (String merchant : merchants) {

            if (appID == null) {
                pst.setNull(1, Types.INTEGER);
            } else {
                pst.setInt(1, appID);
            }
            pst.setInt(2, operatorid);
            pst.setString(3, subscriber);
            pst.setString(4, merchant);
            pst.addBatch();
        }

        log.debug("sql query in insertBlacklistAggregatoRows : " + pst);

        pst.executeBatch();

        /**
         * commit the transaction if all success
         */
        con.commit();
    } catch (SQLException e) {

        log.error("database operation error in insertBlacklistAggregatoRows : ", e);
        /**
         * rollback if Exception occurs
         */
        con.rollback();

        /**
         * throw it into upper layer
         */
        throw e;
    } catch (Exception e) {

        log.error("error in insertBlacklistAggregatoRows : ", e);
        /**
         * rollback if Exception occurs
         */
        con.rollback();

        /**
         * throw it into upper layer
         */
        throw e;
    } finally {

        DbUtils.closeAllConnections(pst, con, null);
    }
}

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

/**
 * Get one value into DbValue from ResultSet
 * /*from  w  ww .  ja  v a  2  s. c  o m*/
 * @param rs
 * @param value
 * @throws WaarpDatabaseSqlException
 */
static public void getTrueValue(ResultSet rs, DbValue value) throws WaarpDatabaseSqlException {
    try {
        switch (value.type) {
        case Types.VARCHAR:
            value.value = rs.getString(value.column);
            break;
        case Types.LONGVARCHAR:
            value.value = rs.getString(value.column);
            break;
        case Types.BIT:
            value.value = rs.getBoolean(value.column);
            break;
        case Types.TINYINT:
            value.value = rs.getByte(value.column);
            break;
        case Types.SMALLINT:
            value.value = rs.getShort(value.column);
            break;
        case Types.INTEGER:
            value.value = rs.getInt(value.column);
            break;
        case Types.BIGINT:
            value.value = rs.getLong(value.column);
            break;
        case Types.REAL:
            value.value = rs.getFloat(value.column);
            break;
        case Types.DOUBLE:
            value.value = rs.getDouble(value.column);
            break;
        case Types.VARBINARY:
            value.value = rs.getBytes(value.column);
            break;
        case Types.DATE:
            value.value = rs.getDate(value.column);
            break;
        case Types.TIMESTAMP:
            value.value = rs.getTimestamp(value.column);
            break;
        case Types.CLOB:
            value.value = rs.getClob(value.column).getCharacterStream();
            break;
        case Types.BLOB:
            value.value = rs.getBlob(value.column).getBinaryStream();
            break;
        default:
            throw new WaarpDatabaseSqlException("Type not supported: " + value.type + " for " + value.column);
        }
    } catch (SQLException e) {
        DbSession.error(e);
        throw new WaarpDatabaseSqlException("Getting values in error: " + value.type + " for " + value.column,
                e);
    }
}

From source file:funcoes.funcoes.java

@SuppressWarnings("rawtypes")
public static Vector<Comparable> proximaLinha(ResultSet rs, ResultSetMetaData rsmd) throws SQLException {
    Vector<Comparable> LinhaAtual = new Vector<Comparable>();

    try {/*w ww .  ja va 2 s . c  o  m*/
        for (int i = 1; i <= rsmd.getColumnCount(); ++i) {
            switch (rsmd.getColumnType(i)) {

            case Types.VARCHAR:
                LinhaAtual.addElement(rs.getString(i));
                break;
            case Types.TIMESTAMP:
                LinhaAtual.addElement(rs.getDate(i).toLocaleString().substring(0, 10));
                break;
            case Types.INTEGER:
                LinhaAtual.addElement(rs.getInt(i));
                break;
            case Types.DECIMAL:
                LinhaAtual.addElement(funcoes.paraFormatoDinheiro(rs.getDouble(i)));
                break;
            case Types.DOUBLE:
                LinhaAtual.addElement(funcoes.paraFormatoDinheiro(rs.getDouble(i)));
                break;

            }
        }
    } catch (SQLException e) {
    }
    return LinhaAtual;

}

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

public MutableResponseHeader loadResponseHeader(int id) throws DataAccessException {
    try {/*from   w w  w.jav a  2 s.c o  m*/
        MapSqlParameterSource params = new MapSqlParameterSource();
        params.addValue(ID, id, Types.INTEGER);
        SimpleJdbcTemplate template = new SimpleJdbcTemplate(getNamedParameterJdbcTemplate());
        return template.queryForObject(SELECT_RESPONSE, RESPONSE_MAPPER, params);
    } catch (EmptyResultDataAccessException erdae) {
        return null;
    }
}

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

public static IDomain computeDomain(int data_type, int size, int scale) {
    switch (data_type) {
    case Types.BOOLEAN:
    case Types.BIT:// on PG systems, this is how a boolean is actually represented by the driver
        return IDomain.BOOLEAN;
    case Types.TINYINT:
    case Types.BIGINT:
    case Types.INTEGER:
    case Types.SMALLINT:
        return IDomain.NUMERIC;
    ///////////////////////////
    case Types.REAL:
    case Types.DOUBLE:
    case Types.FLOAT:
        return IDomain.CONTINUOUS;
    case Types.NUMERIC:
    case Types.DECIMAL:
        return scale > 0 || size == 0 ? IDomain.CONTINUOUS : IDomain.NUMERIC;
    case Types.CHAR:
    case Types.NCHAR:
    case Types.VARCHAR:
    case Types.NVARCHAR:
    case Types.LONGVARCHAR:
    case Types.CLOB:
        return IDomain.STRING;
    ///////////////////////////
    case Types.TIME:
        return IDomain.TIME;
    case Types.DATE:
        return IDomain.DATE;
    case Types.TIMESTAMP:
        return IDomain.TIMESTAMP;
    ///////////////////////////
    default://from ww w  . j  a v  a 2 s. c om
        return IDomain.UNKNOWN;
    }
}