Example usage for java.sql PreparedStatement setInt

List of usage examples for java.sql PreparedStatement setInt

Introduction

In this page you can find the example usage for java.sql PreparedStatement setInt.

Prototype

void setInt(int parameterIndex, int x) throws SQLException;

Source Link

Document

Sets the designated parameter to the given Java int value.

Usage

From source file:com.wwpass.cas.example.JdbcUserServiceDao.java

public void createWwpass(final String puid, final int uid) {
    if (createWwpassAssociationQuery == null) {
        createWwpassAssociationQuery = CREATE_WWPASS_ASSOCIATION;
    }//from  w ww.  j  a v  a 2 s. com
    getJdbcTemplate().update(new PreparedStatementCreator() {
        @Override
        public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
            PreparedStatement ps = con.prepareStatement(createWwpassAssociationQuery);
            ps.setString(1, puid);
            ps.setInt(2, uid);
            return ps;
        }
    });
}

From source file:libepg.ts.aligner.Alligner2.java

public synchronized List<TsPacketParcel> getAllignedPackets() {
    JDBCAccessor ac = JDBCAccessor.getInstance();
    try {//from  w  ww.  j  a va 2s .c  o  m
        ac.connect(AboutDB.URL);
        Connection conn = ac.getConnection();

        Statement stmt = conn.createStatement();
        //?
        stmt.executeUpdate(CRATE_TABLE);

        //?PID??????
        for (TsPacket tsp : this.packets) {
            //                System.out.println(Integer.toHexString(tsp.getPid()));
            if (tsp.getPid() == this.getPid()) {
                PreparedStatement insertStatement = conn.prepareStatement(INSERT_SQL);
                insertStatement.setInt(1, tsp.getPid());
                insertStatement.setInt(2, tsp.getContinuity_counter());
                insertStatement.setInt(3, 0);
                insertStatement.setBytes(4, tsp.getData());
                insertStatement.executeUpdate();
            }
        }

        debug_dump_table(conn);

        //            //
        //            LinkedList<TsPacketParcel> temp = new LinkedList<>();
        //            for (TsPacket tsp : this.packets) {
        //
        //                //??????0
        //                if (tsp.getAdaptation_field_control() == TsPacket.ADAPTATION_FIELD_CONTROL.ONLY_ADAPTATION_FIELD) {
        //                    if (tsp.getContinuity_counter() == 0) {
        //                        temp.add(new TsPacketParcel(tsp, TsPacketParcel.MISSING_PACKET_FLAG.NOT_MISSING));
        //                    } else if (LOG.isWarnEnabled()) {
        //                        LOG.warn("???0????????");
        //                        LOG.warn(tsp);
        //                    }
        //                }
        //
        //                if (LOG.isTraceEnabled()) {
        //                    LOG.trace("????");
        //                }
        //                if (temp.contains(tsp)) {
        //
        //                }
        //            }
    } catch (SQLException ex) {
        LOG.fatal(ex);
    } finally {
        ac.close();
    }
    return null;
}

From source file:de.is24.infrastructure.gridfs.http.metadata.generation.PrimaryDbGenerator.java

private void writePrimaryPackage(PreparedStatement ps, int pkgKey, YumPackage p) throws SQLException {
    int c = 1;/*from w w w . j a  v a  2s .c om*/
    ps.setInt(c++, pkgKey);
    ps.setString(c++, p.getChecksum().getChecksum());
    ps.setString(c++, p.getName());
    ps.setString(c++, p.getArch());
    ps.setString(c++, p.getVersion().getVer());
    ps.setInt(c++, p.getVersion().getEpoch());
    ps.setString(c++, p.getVersion().getRel());
    ps.setString(c++, trim(p.getSummary()));
    ps.setString(c++, trim(p.getDescription()));
    ps.setString(c++, defaultIfBlank(p.getUrl(), null));
    ps.setInt(c++, p.getTime().getFile());
    ps.setInt(c++, p.getTime().getBuild());
    ps.setString(c++, emptyIfBlank(p.getPackageFormat().getLicense()));
    ps.setString(c++, emptyIfBlank(p.getPackageFormat().getVendor()));
    ps.setString(c++, emptyIfBlank(p.getPackageFormat().getGroup()));
    ps.setString(c++, emptyIfBlank(p.getPackageFormat().getBuildHost()));
    ps.setString(c++, emptyIfBlank(p.getPackageFormat().getSourceRpm()));
    ps.setInt(c++, p.getPackageFormat().getHeaderStart());
    ps.setInt(c++, p.getPackageFormat().getHeaderEnd());
    ps.setString(c++, nullIfBlank(p.getPackager()));
    ps.setInt(c++, p.getSize().getPackaged());
    ps.setInt(c++, p.getSize().getInstalled());
    ps.setInt(c++, p.getSize().getArchive());
    ps.setString(c++, p.getLocation().getHref());
    ps.setString(c++, null);
    ps.setString(c, p.getChecksum().getType());
    ps.executeUpdate();
}

From source file:com.fpmislata.banco.persistencia.impl.SucursalBancariaDAOImplJDBC.java

@Override
public SucursalBancaria get(int id) {
    Connection connection = (Connection) connectionFactory.getConnection();
    SucursalBancaria sucursalBancaria = new SucursalBancaria();
    String SQL = "SELECT * FROM sucursalbancaria WHERE id = ?";

    try {//from w  w w  .j  a  v  a 2 s .c  om

        PreparedStatement preparedStatement = connection.prepareStatement(SQL);
        preparedStatement.setInt(1, id);

        ResultSet resultSet = preparedStatement.executeQuery();

        while (resultSet.next()) {
            sucursalBancaria.setId(resultSet.getInt(1));
            sucursalBancaria.setEntidadPertenece(resultSet.getInt(2));
            sucursalBancaria.setCodigoSucursal(resultSet.getString(3));
            sucursalBancaria.setNombreSucursal(resultSet.getString(4));
        }
        return sucursalBancaria;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    } finally {
        try {
            connection.close();
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }
}

From source file:de.ingrid.importer.udk.strategy.v30.IDCStrategy3_0_0_fixFreeEntry.java

/** Read value of syslist entry from database !
 * @param listId id of syslist/*from w  w w  . j av a2s  .  c om*/
 * @param entryId id of antry
 * @param language language of entry
 * @return returns null if not found
 * @throws Exception
 */
protected String readSyslistValue(int listId, int entryId, String language) throws Exception {
    String retValue = null;

    sqlStr = "SELECT name FROM sys_list WHERE lst_id = ? and entry_id = ? and lang_id = ?";
    PreparedStatement ps = jdbc.prepareStatement(sqlStr);
    ps.setInt(1, listId);
    ps.setInt(2, entryId);
    ps.setString(3, language);

    ResultSet rs = ps.executeQuery();
    while (rs.next()) {
        retValue = rs.getString("name");
    }
    rs.close();
    ps.close();

    return retValue;
}

From source file:com.assignment4.products.Pro_details.java

@DELETE
@Path("{id}")
@Consumes(MediaType.TEXT_PLAIN)// w  w w . j a  va 2 s.  c  o m
@Produces(MediaType.TEXT_PLAIN)
public String deleteProduct(@PathParam("id") int id) throws SQLException {

    if (conn == null) {
        return "not connected";
    } else {
        String q = "DELETE FROM products WHERE product_id = ?";
        PreparedStatement ps = conn.prepareStatement(q);
        ps.setInt(1, id);
        ps.executeUpdate();
        return "The specified row is deleted";

    }

}

From source file:com.l2jfree.gameserver.instancemanager.FortSiegeGuardManager.java

/**
 * Load guards.<BR><BR>/*  www  .j a va 2  s . c  om*/
 */
void loadSiegeGuard() {
    _siegeGuards.clear();
    Connection con = null;
    try {
        con = L2DatabaseFactory.getInstance().getConnection(con);
        PreparedStatement statement = con.prepareStatement("SELECT * FROM fort_siege_guards Where fortId = ? ");
        statement.setInt(1, getFort().getFortId());
        ResultSet rs = statement.executeQuery();

        L2Spawn spawn1;
        L2NpcTemplate template1;

        _siegeGuardsSpawns = new FastList<L2Spawn>();
        while (rs.next()) {
            int fortId = rs.getInt("fortId");
            template1 = NpcTable.getInstance().getTemplate(rs.getInt("npcId"));
            if (template1 != null) {
                spawn1 = new L2Spawn(template1);
                spawn1.setId(rs.getInt("id"));
                spawn1.setAmount(1);
                spawn1.setLocx(rs.getInt("x"));
                spawn1.setLocy(rs.getInt("y"));
                spawn1.setLocz(rs.getInt("z"));
                spawn1.setHeading(rs.getInt("heading"));
                spawn1.setRespawnDelay(rs.getInt("respawnDelay"));
                spawn1.setLocation(0);

                _siegeGuardsSpawns.add(spawn1);
            } else {
                _log.warn("Missing npc data in npc table for id: " + rs.getInt("npcId"));
            }
            _siegeGuards.put(fortId, _siegeGuardsSpawns);
        }
        rs.close();
        statement.close();
    } catch (Exception e1) {
        _log.warn("Error loading siege guard for fort " + getFort().getName() + ":", e1);
    } finally {
        L2DatabaseFactory.close(con);
    }
}

From source file:net.freechoice.model.orm.Map_Comment.java

@Override
public PreparedStatementCreator createUpdate(final FC_Comment entity) {

    return new PreparedStatementCreator() {
        @Override//from   ww w . j ava2s . com
        public PreparedStatement createPreparedStatement(Connection con) throws SQLException {

            PreparedStatement ps = con.prepareStatement("update FC_Comment set id_post_= ? " + ",  email = ?"
                    + ",  name = ?" + ",  comment = ?" + " where id = ?");//
            ps.setInt(1, entity.id_post_);
            ps.setString(2, entity.email);
            ps.setString(3, entity.name);
            ps.setString(4, entity.comment);
            ps.setInt(5, entity.id);
            return ps;
        }
    };
}

From source file:org.chimi.s4s.metainfo.mysql.MysqlMetaInfoDaoTest.java

private void assertData(String id, FileMetadata metadata) throws Throwable {
    Connection conn = dataSource.getConnection();
    PreparedStatement pstmt = conn.prepareStatement("select * from FILE_METADATA where FILE_METADATA_ID = ?");
    int idValue = Integer.parseInt(id);
    pstmt.setInt(1, idValue);
    ResultSet rs = pstmt.executeQuery();

    assertTrue(rs.next());/*from  ww w. j a va  2  s  .  c  o  m*/
    assertEquals(idValue, rs.getInt("FILE_METADATA_ID"));
    assertEquals(metadata.getServiceId(), rs.getString("SERVICE_ID"));
    assertEquals(metadata.getFileName(), rs.getString("FILE_NAME"));
    assertEquals(metadata.getLength(), rs.getLong("FILE_LENGTH"));
    assertEquals(metadata.getMimetype(), rs.getString("MIMETYPE"));
    SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
    assertEquals(format.format(metadata.getUploadTime()), format.format(rs.getTimestamp("UPLOAD_TIME")));
    assertEquals(metadata.getFileId(), rs.getString("FILE_ID"));

    rs.close();
    pstmt.close();
    conn.close();
}

From source file:libepg.util.db.JDBCAccessorTest.java

/**
 * Test of getConnection method, of class JDBCAccessor.
 *
 *//*from   w  ww .ja va  2s .  c  o m*/
@Test
public void testGetCon() {
    try {

        LOG.info("getCon");
        JDBCAccessor instance = JDBCAccessor.getInstance();
        String url = "jdbc:sqlite::memory:";
        instance.connect(url);
        java.sql.Connection result = instance.getConnection();
        assertNotNull(result);
        LOG.debug("Connected.");

        Statement stmt = result.createStatement();
        //?
        stmt.executeUpdate("create table test1( name string, age integer )");
        LOG.debug("Made table.");

        //?
        String nameVal = "jjj888???";
        int ageVal = 778;
        String sql1 = "insert into test1 values (?,?)";
        PreparedStatement pstmt1 = result.prepareStatement(sql1);
        pstmt1.setString(1, nameVal);
        pstmt1.setInt(2, ageVal);
        pstmt1.executeUpdate();
        LOG.debug("Inserted.");

        //??
        String sql2 = "select * from test1 where name=? and age=?";
        PreparedStatement pstmt2 = result.prepareStatement(sql2);
        pstmt2.setString(1, nameVal);
        pstmt2.setInt(2, ageVal);
        ResultSet rs = pstmt2.executeQuery();
        while (rs.next()) {
            String str1 = rs.getString("name");
            int int2 = rs.getInt("age");
            System.out.println(str1);
            System.out.println(int2);
            assertEquals(nameVal, str1);
            assertEquals(ageVal, int2);
        }
        LOG.debug("Got data.");

    } catch (SQLException ex) {
        LOG.fatal(ex);
        fail();
    } finally {
        JDBCAccessor.getInstance().close();
    }
}