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 void saveRequestHeader(MutableRequestHeader requestHeader, int contentId) throws DataAccessException {
    saveMessageHeader(requestHeader, contentId);
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue(ID, requestHeader.getId(), Types.INTEGER);
    params.addValue(HOST, requestHeader.getTarget().getHostName(), Types.VARCHAR);
    params.addValue(PORT, requestHeader.getTarget().getPort(), Types.INTEGER);
    params.addValue(SSL, requestHeader.isSsl(), Types.BIT);
    addTimestamp(params, REQUEST_SUBMISSION_TIME, requestHeader.getTime());
    getNamedParameterJdbcTemplate().update(INSERT_REQUEST, params);
}

From source file:org.jetbrains.webdemo.database.MySqlConnector.java

private String addProject(UserInfo userInfo, Project project, String type, Integer taskId)
        throws DatabaseOperationException {
    if (!checkCountOfProjects(userInfo)) {
        throw new DatabaseOperationException("You can't save more than 100 projects");
    }//  ww  w . j  av  a  2 s . c  o  m

    int userId = getUserId(userInfo);

    PreparedStatement st = null;
    try (Connection connection = dataSource.getConnection()) {
        String publicId = idGenerator.nextProjectId();

        st = connection.prepareStatement(
                "INSERT INTO projects (owner_id, name, args, run_configuration, origin, public_id, read_only_files, type, task_id) VALUES (?,?,?,?,?,?,?,?,?) ");
        st.setString(1, userId + "");
        st.setString(2, escape(project.name));
        st.setString(3, project.args);
        st.setString(4, project.confType);
        st.setString(5, project.originUrl);
        st.setString(6, publicId);
        st.setString(7, objectMapper.writeValueAsString(project.readOnlyFileNames));
        st.setString(8, type);
        if (taskId == null) {
            st.setNull(9, Types.INTEGER);
        } else {
            st.setInt(9, taskId);
        }
        st.execute();

        int projectId = getProjectId(userInfo, publicId);
        for (ProjectFile file : project.files) {
            addFileToProject(userInfo, projectId, file.getName(), file.getText());
        }

        return publicId;
    } catch (SQLException e) {
        if (e.getErrorCode() == 1062) {
            throw new DatabaseOperationException("Project with this name already exist", e);
        } else {
            ErrorWriter.ERROR_WRITER.writeExceptionToExceptionAnalyzer(e,
                    SessionInfo.TypeOfRequest.WORK_WITH_DATABASE.name(), "unknown",
                    "Add project " + userInfo.getId() + " " + userInfo.getType() + " " + userInfo.getName()
                            + " " + project.name);
            throw new DatabaseOperationException("Unknown exception", e);
        }
    } catch (Throwable e) {
        ErrorWriter.ERROR_WRITER.writeExceptionToExceptionAnalyzer(e,
                SessionInfo.TypeOfRequest.WORK_WITH_DATABASE.name(), "unknown",
                "Add project " + userInfo.getId() + " " + userInfo.getType() + " " + userInfo.getName() + " "
                        + project.name);
        throw new DatabaseOperationException("Unknown exception", e);
    } finally {
        closeStatement(st);
    }
}

From source file:com.mobiaware.auction.data.impl.MySqlDataServiceImpl.java

@Override
public double addFund(final Fund fund) {
    int uid = -1;

    Connection conn = null;/*from  w w  w .  j a  v  a 2  s. c  om*/
    CallableStatement stmt = null;

    try {
        conn = _dataSource.getConnection();

        stmt = conn.prepareCall("{call SP_EDITFUND (?,?,?,?)}");
        stmt.registerOutParameter(1, Types.INTEGER);
        stmt.setInt(2, fund.getAuctionUid());
        stmt.setInt(3, fund.getUserUid());
        stmt.setDouble(4, fund.getBidPrice());

        stmt.execute();

        uid = stmt.getInt(1);
    } catch (SQLException e) {
        LOG.error(Throwables.getStackTraceAsString(e));
    } finally {
        DbUtils.closeQuietly(conn, stmt, null);
    }

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

    double sum = 0.0;

    ResultSet rs = null;

    try {
        conn = _dataSource.getConnection();

        stmt = conn.prepareCall("{call SP_GETFUNDSUM (?)}");
        stmt.setInt(1, fund.getAuctionUid());

        rs = stmt.executeQuery();

        if (rs.next()) {
            sum = rs.getDouble(1);
        }
    } catch (SQLException e) {
        LOG.error(Throwables.getStackTraceAsString(e));
    } finally {
        DbUtils.closeQuietly(conn, stmt, rs);
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("FUND [method:{} result:{}]", new Object[] { "sum", sum });
    }

    return sum;
}

From source file:ch.rgw.tools.JdbcLink.java

public static int generalType(int t) {
    switch (t) {//from ww w .  j a  v a  2s  . c  o m
    case Types.BIGINT:
    case Types.BIT:
    case Types.BOOLEAN:
    case Types.INTEGER:
    case Types.SMALLINT:
    case Types.TINYINT:
        return INTEGRAL;

    case Types.VARCHAR:
    case Types.CHAR:
    case Types.LONGVARCHAR:
        return TEXT;

    case Types.BINARY:
    case Types.BLOB:
    case Types.CLOB:
    case Types.LONGVARBINARY:
    case Types.VARBINARY:
        return BINARY;

    default:
        return OTHER;

    }
}

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

public void saveResponseHeader(MutableResponseHeader responseHeader, int contentId) throws DataAccessException {
    saveMessageHeader(responseHeader, contentId);
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue(ID, responseHeader.getId(), Types.INTEGER);
    addTimestamp(params, RESPONSE_HEADER_TIME, responseHeader.getHeaderTime());
    addTimestamp(params, RESPONSE_CONTENT_TIME, responseHeader.getContentTime());
    getNamedParameterJdbcTemplate().update(INSERT_RESPONSE, params);
}

From source file:com.streamsets.pipeline.lib.jdbc.multithread.TableContextUtil.java

public static String generateNextPartitionOffset(TableContext tableContext, String column, String offset) {
    final String partitionSize = tableContext.getOffsetColumnToPartitionOffsetAdjustments().get(column);
    switch (tableContext.getOffsetColumnToType().get(column)) {
    case Types.TINYINT:
    case Types.SMALLINT:
    case Types.INTEGER:
        final int int1 = Integer.parseInt(offset);
        final int int2 = Integer.parseInt(partitionSize);
        return String.valueOf(int1 + int2);
    case Types.TIMESTAMP:
        final Timestamp timestamp1 = getTimestampForOffsetValue(offset);
        final long timestampAdj = Long.parseLong(partitionSize);
        final Timestamp timestamp2 = Timestamp.from(timestamp1.toInstant().plusMillis(timestampAdj));
        return getOffsetValueForTimestamp(timestamp2);
    case Types.BIGINT:
        // TIME, DATE are represented as long (epoch)
    case Types.TIME:
    case Types.DATE:
        final long long1 = Long.parseLong(offset);
        final long long2 = Long.parseLong(partitionSize);
        return String.valueOf(long1 + long2);
    case Types.FLOAT:
    case Types.REAL:
        final float float1 = Float.parseFloat(offset);
        final float float2 = Float.parseFloat(partitionSize);
        return String.valueOf(float1 + float2);
    case Types.DOUBLE:
        final double double1 = Double.parseDouble(offset);
        final double double2 = Double.parseDouble(partitionSize);
        return String.valueOf(double1 + double2);
    case Types.NUMERIC:
    case Types.DECIMAL:
        final BigDecimal decimal1 = new BigDecimal(offset);
        final BigDecimal decimal2 = new BigDecimal(partitionSize);
        return decimal1.add(decimal2).toString();
    }/*from  w  w w.j  a  v  a2 s.c  o  m*/
    return null;
}

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

/**
 * ???????/*  ww w .  j  a v a 2  s.com*/
 */
public static int saveDeclProduct(String declNo, String entProductCode, String baseCode, String goodsNo) {
    int retCode = -1;
    Connection conn = null;
    CallableStatement proc = null;
    ResultSet rs = null;
    String call = "{call Pro_SaveDeclProduct(?,?,?,?,?)}";
    try {
        conn = DBPool.ds.getConnection();
        proc = conn.prepareCall(call);
        proc.setString(1, declNo);
        proc.setString(2, entProductCode);
        proc.setString(3, baseCode);
        proc.setString(4, goodsNo);
        proc.registerOutParameter(5, Types.INTEGER);
        proc.execute();
        retCode = proc.getInt(5);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        log.error("N54", e);
    } catch (Exception e) {
        log.error("N55", 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("N56", e);
        }
    }
    return retCode;
}

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

private void saveMessageHeader(MutableMessageHeader header, int contentId) {
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue(HEADER, header.getHeader(), Types.LONGVARBINARY);
    params.addValue(CONTENTID, contentId != -1 ? contentId : null, Types.INTEGER);
    KeyHolder key = new GeneratedKeyHolder();
    getNamedParameterJdbcTemplate().update(INSERT_HEADER, params, key);
    header.setId(key.getKey().intValue());
}

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

public void testAddColAtFirstIdx() throws SQLObjectException {
    table.addColumn(new SQLColumn(table, "zero", Types.INTEGER, 10, 0), 0);
    assertEquals(7, table.getColumns().size());
    assertEquals(4, table.getPkSize());//from   w  w w .  jav a 2s  . co m

    assertTrue(table.getColumnByName("zero").isPrimaryKey());
    assertEquals(0, table.getColumnIndex(table.getColumnByName("zero")));
    assertEquals(1, table.getColumnIndex(table.getColumnByName("one")));
    assertEquals(2, table.getColumnIndex(table.getColumnByName("two")));
    assertEquals(3, table.getColumnIndex(table.getColumnByName("three")));
    assertEquals(4, table.getColumnIndex(table.getColumnByName("four")));
    assertEquals(5, table.getColumnIndex(table.getColumnByName("five")));
    assertEquals(6, table.getColumnIndex(table.getColumnByName("six")));
}

From source file:com.funambol.foundation.items.dao.PIMNoteDAO.java

public String updateItem(NoteWrapper nw) throws DAOException {

    Connection con = null;// w w  w  .j  a  va2  s  .c o  m
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {

        //
        // Note fields
        //
        Note note = nw.getNote();

        StringBuilder updateQuery = new StringBuilder();

        updateQuery.append(SQL_UPDATE_FNBL_PIM_NOTE_BEGIN);

        updateQuery.append(SQL_FIELD_LAST_UPDATE + SQL_EQUALS_QUESTIONMARK_COMMA);
        updateQuery.append(SQL_FIELD_STATUS + SQL_EQUALS_QUESTIONMARK_COMMA);

        String subject = note.getSubject().getPropertyValueAsString();
        if (subject != null) {
            updateQuery.append(SQL_FIELD_SUBJECT + SQL_EQUALS_QUESTIONMARK_COMMA);
        }

        String textDescription = note.getTextDescription().getPropertyValueAsString();
        if (textDescription != null) {
            updateQuery.append(SQL_FIELD_TEXTDESCRIPTION + SQL_EQUALS_QUESTIONMARK_COMMA);

            updateQuery.append(SQL_FIELD_CRC + SQL_EQUALS_QUESTIONMARK_COMMA);
        }

        String categories = note.getCategories().getPropertyValueAsString();
        if (categories != null) {
            updateQuery.append(SQL_FIELD_CATEGORIES + SQL_EQUALS_QUESTIONMARK_COMMA);
        }

        String folder = note.getFolder().getPropertyValueAsString();
        if (folder != null) {
            updateQuery.append(SQL_FIELD_FOLDER + SQL_EQUALS_QUESTIONMARK_COMMA);
        }
        String color = note.getColor().getPropertyValueAsString();
        if (color != null) {
            updateQuery.append(SQL_FIELD_COLOR + SQL_EQUALS_QUESTIONMARK_COMMA);
        }

        String height = note.getHeight().getPropertyValueAsString();
        if (height != null) {
            updateQuery.append(SQL_FIELD_HEIGHT + SQL_EQUALS_QUESTIONMARK_COMMA);
        }

        String width = note.getWidth().getPropertyValueAsString();
        if (width != null) {
            updateQuery.append(SQL_FIELD_WIDTH + SQL_EQUALS_QUESTIONMARK_COMMA);
        }

        String top = note.getTop().getPropertyValueAsString();
        if (top != null) {
            updateQuery.append(SQL_FIELD_TOP + SQL_EQUALS_QUESTIONMARK_COMMA);
        }

        String left = note.getLeft().getPropertyValueAsString();
        if (left != null) {
            updateQuery.append(SQL_FIELD_LEFT_MARGIN + SQL_EQUALS_QUESTIONMARK_COMMA);
        }

        if (updateQuery.charAt(updateQuery.length() - 2) == ',') {
            updateQuery.deleteCharAt(updateQuery.length() - 2);
        }

        updateQuery.append(SQL_UPDATE_FNBL_PIM_NOTE_END);

        // Looks up the data source when the first connection is created
        con = getUserDataSource().getRoutedConnection(userId);

        ps = con.prepareStatement(updateQuery.toString());

        int k = 1;

        //
        // last update
        //
        Timestamp lastUpdate = (nw.getLastUpdate() == null) ? new Timestamp(System.currentTimeMillis())
                : nw.getLastUpdate();
        ps.setLong(k++, lastUpdate.getTime());

        //
        // status
        //
        ps.setString(k++, String.valueOf(Def.PIM_STATE_UPDATED));

        //
        // subject
        //
        if (subject != null) {
            ps.setString(k++, StringUtils.left(subject, SQL_SUBJECT_DIM));
        }

        //
        // textDescription
        //
        if (textDescription != null) {
            textDescription = textDescription.replace('\0', ' ');
            String truncatedTextDescription = StringUtils.left(textDescription, SQL_TEXTDESCRIPTION_DIM);

            ps.setString(k++, truncatedTextDescription);
            ps.setLong(k++, calculateCrc(truncatedTextDescription));
        }

        //
        // categories
        //
        if (categories != null) {
            ps.setString(k++, truncateCategoriesField(categories, SQL_CATEGORIES_DIM));
        }

        //
        // folder
        //
        if (folder != null) {
            ps.setString(k++, truncateFolderField(folder, SQL_FOLDER_DIM));
        }

        //
        // color
        //
        if (color != null) {
            if (color.length() == 0) {
                ps.setNull(k++, Types.INTEGER);
            } else {
                ps.setInt(k++, Integer.parseInt(color));
            }
        }

        //
        // height
        //
        if (height != null) {
            if (height.length() == 0) {
                ps.setNull(k++, Types.INTEGER);
            } else {
                ps.setInt(k++, Integer.parseInt(height));
            }
        }

        //
        // width
        //
        if (width != null) {
            if (width.length() == 0) {
                ps.setNull(k++, Types.INTEGER);
            } else {
                ps.setInt(k++, Integer.parseInt(width));
            }
        }

        //
        // top
        //
        if (top != null) {
            if (top.length() == 0) {
                ps.setNull(k++, Types.INTEGER);
            } else {
                ps.setInt(k++, Integer.parseInt(top));
            }
        }

        //
        // left
        //
        if (left != null) {
            if (left.length() == 0) {
                ps.setNull(k++, Types.INTEGER);
            } else {
                ps.setInt(k++, Integer.parseInt(left));
            }
        }

        //
        // id
        //
        ps.setLong(k++, Long.parseLong(nw.getId()));
        //
        // userId
        //
        ps.setString(k++, userId);

        ps.executeUpdate();

        DBTools.close(null, ps, null);
    } catch (Exception e) {
        throw new DAOException("Error updating note.", e);
    } finally {
        DBTools.close(con, ps, rs);
    }

    return nw.getId();
}