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:cai.flow.packets.V8_FlowSrcPrefix.java

void fill_specific(PreparedStatement add_raw_stm) throws SQLException {
    add_raw_stm.setString(13, Util.str_addr(src_prefix));
    add_raw_stm.setInt(14, (int) src_mask);
    add_raw_stm.setInt(15, (int) src_as);
    add_raw_stm.setInt(16, (int) input);
    add_raw_stm.setString(17, Params.getCurrentTime());
}

From source file:dhbw.clippinggorilla.objects.user.UserUtils.java

/**
 * removes a clipping send time from the users set.
 *
 * @param u The User which Clipping sending time should be removed
 * @param time time to remove, has to be in the users ClippingSendTimes!
 * @return true if successful/*from  w  ww.  j  a v a2  s . c om*/
 */
public static boolean removeClippingSendTime(User u, LocalTime time) {
    if (u.getClippingTime().contains(time)) {
        String sql = "DELETE FROM " + Tables.USER_CLIPPING_TIMES + " WHERE " + Columns.USER_ID + " = ? AND "
                + Columns.CLIPPING_TIME + " = ?";
        try {
            PreparedStatement statement = Database.getConnection().prepareStatement(sql);
            statement.setInt(1, u.getId());
            statement.setString(2, time.toString());
            statement.executeUpdate();
        } catch (SQLException ex) {
            Log.warning("Sql failed: deleteClippingTime", ex);
            return false;
        }
        u.getClippingTime().remove(time);
        Jobs.updateClippingGenerationTimes(u, u.getClippingTime());
        return true;
    }
    return false;
}

From source file:controladores.PeliculasController.java

public ModelAndView verMas(HttpServletRequest request, HttpServletResponse response) throws Exception {
    int pid = Integer.valueOf(request.getParameter("pid"));
    this.getConnection(request.getServletContext());
    Pelicula p = null;// ww w .j  a  va 2  s  .  com
    try {
        PreparedStatement ps = this.conexion.prepareStatement(
                "SELECT ids, nombre, observaciones, tipopeli, precio, foto FROM peliculas WHERE ids = ?");
        ps.setInt(1, pid);
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            p = new Pelicula(rs.getInt("ids"), rs.getString("nombre"), rs.getString("tipopeli"),
                    rs.getString("observaciones"), rs.getInt("precio"), rs.getString("foto").toUpperCase());
        }
        rs.close();
    } catch (SQLException ex) {
        ex.printStackTrace();
    }
    ModelAndView mv;
    if (p != null) {
        mv = new ModelAndView("detalles");
        mv.addObject("pelicula", p);
    } else {
        mv = this.inicio(request, response);
    }
    mv.addObject("metodo", "verMas");
    return mv;
}

From source file:com.Assignment4.Assign.java

@POST
@Consumes(MediaType.APPLICATION_JSON)/*from   w  w w.j ava  2s . c  o  m*/
@Produces(MediaType.TEXT_PLAIN)
public String postProduct(String str) throws SQLException {
    JsonParser parser = Json.createParser(new StringReader(str));
    Map<String, String> proMap = new LinkedHashMap<String, String>();
    String key = "";
    String val = "";

    while (parser.hasNext()) {
        JsonParser.Event event = parser.next();
        switch (event) {
        case KEY_NAME:
            key = parser.getString();
            break;
        case VALUE_STRING:
            val = parser.getString();
            proMap.put(key, val);
            break;
        case VALUE_NUMBER:
            val = parser.getString();
            proMap.put(key, val);
            break;
        default:
            break;
        }
    }
    if (connected == null) {
        return "Not connected";
    } else {
        String query = "INSERT INTO product (product_id,name,description,quantity) VALUES (?,?,?,?)";
        PreparedStatement pst = connected.prepareStatement(query);
        pst.setInt(1, Integer.parseInt(proMap.get("product_id")));
        pst.setString(2, proMap.get("name"));
        pst.setString(3, proMap.get("description"));
        pst.setInt(4, Integer.parseInt(proMap.get("quantity")));
        pst.executeUpdate();
        return "row has been inserted into the database";
    }

}

From source file:at.alladin.rmbt.db.dao.QoSTestResultDao.java

/**
 * /*w w  w.  j a v a2 s.co m*/
 * @param result
 * @param columnNames
 * @throws SQLException
 */
public int updateCounter(QoSTestResult result, PreparedStatement ps) throws SQLException {
    ps.setInt(1, result.getSuccessCounter());
    ps.setInt(2, result.getFailureCounter());
    ps.setLong(3, result.getUid());
    return ps.executeUpdate();
}

From source file:dhbw.clippinggorilla.objects.user.UserUtils.java

/**
 * Returns true if activationKey is correct and updates AccessLevel to 20
 *
 * @param u The User who should be activated
 * @param activationKey The key send via email to activate the user
 * @return true if the key is correct, false otherwise
 *//*from  w ww  .ja v  a 2 s  .  co  m*/
public static synchronized boolean activateUser(User u, String activationKey) {
    if (u.getActivationKey().equals(activationKey)) {
        try {
            String sql = "UPDATE " + Tables.USER + " SET " + Columns.STATUS + " = ? WHERE " + Columns.ID
                    + " = ?";
            PreparedStatement statement = Database.getConnection().prepareStatement(sql);
            statement.setInt(1, 20);
            statement.setInt(2, u.getId());
            statement.executeUpdate();
            u.setAccessLevel(20);
            return true;
        } catch (SQLException ex) {
            Log.warning("SQLException on account activation: ", ex);
            return false;
        }
    } else {
        Log.debug("Ceck failed, not equal!");
        return false;

    }
}

From source file:com.Assignment4.Prod.java

@POST
@Consumes(MediaType.APPLICATION_JSON)/*  ww w . j  av a2s.c om*/
@Produces(MediaType.TEXT_PLAIN)
public String postProduct(String str) throws SQLException {
    JsonParser parser = Json.createParser(new StringReader(str));
    Map<String, String> pMap = new LinkedHashMap<String, String>();
    String key = "";
    String val = "";

    while (parser.hasNext()) {
        JsonParser.Event event = parser.next();
        switch (event) {
        case KEY_NAME:
            key = parser.getString();
            break;
        case VALUE_STRING:
            val = parser.getString();
            pMap.put(key, val);
            break;
        case VALUE_NUMBER:
            val = parser.getString();
            pMap.put(key, val);
            break;
        default:
            break;
        }
    }
    if (connect == null) {
        return "Not connected";
    } else {
        String query = "INSERT INTO product (product_id,name,description,quantity) VALUES (?,?,?,?)";
        PreparedStatement prepstmt = connect.prepareStatement(query);
        prepstmt.setInt(1, Integer.parseInt(pMap.get("product_id")));
        prepstmt.setString(2, pMap.get("name"));
        prepstmt.setString(3, pMap.get("description"));
        prepstmt.setInt(4, Integer.parseInt(pMap.get("quantity")));
        prepstmt.executeUpdate();
        return "row has been inserted into the database";
    }

}

From source file:oobbit.orm.LinkConnections.java

public void delete(int sourceId, int destinationId) throws SQLException {
    PreparedStatement statement = getConnection().prepareStatement(
            "DELETE FROM `oobbit`.`connections` WHERE `connections`.`source_link_id` = ? AND `connections`.`destination_link_id` = ?;");
    statement.setInt(1, sourceId);
    statement.setInt(2, destinationId);//from w  ww. ja  va  2 s.c  om

    statement.executeUpdate();
    statement.close();
}

From source file:com.concursive.connect.web.modules.register.beans.RegisterBean.java

/**
 * Description of the Method//  w  w w  .j av  a 2s .c o m
 *
 * @param db                Description of the Parameter
 * @param partialUserRecord Description of the Parameter
 * @return Description of the Return Value
 * @throws SQLException Description of the Exception
 */
private static void updateRegisteredStatus(Connection db, User partialUserRecord) throws SQLException {
    // NOTE: Assume the user object isn't complete, so can't load it, etc.
    {
        // Approve the user
        PreparedStatement pst = db
                .prepareStatement("UPDATE users " + "SET first_name = ?, last_name = ?, password = ?, "
                        + "company = ?, registered = ?, enabled = ?, terms = ? " + "WHERE user_id = ? ");
        int i = 0;
        pst.setString(++i, partialUserRecord.getFirstName());
        pst.setString(++i, partialUserRecord.getLastName());
        pst.setString(++i, partialUserRecord.getPassword());
        pst.setString(++i, partialUserRecord.getCompany());
        pst.setBoolean(++i, true);
        pst.setBoolean(++i, true);
        pst.setBoolean(++i, partialUserRecord.getTerms());
        pst.setInt(++i, partialUserRecord.getId());
        pst.executeUpdate();
        pst.close();
        CacheUtils.invalidateValue(Constants.SYSTEM_USER_CACHE, partialUserRecord.getId());
    }

    {
        // Approve the user's profile and update their location
        User user = UserUtils.loadUser(partialUserRecord.getId());
        if (user == null) {
            LOG.warn("updateRegisteredStatus - USER RECORD IS NULL");
        } else {
            Project profile = ProjectUtils.loadProject(user.getProfileProjectId());
            if (profile == null) {
                LOG.warn("updateRegisteredStatus - PROFILE RECORD IS NULL");
            } else {
                profile.setApproved(true);
                profile.setCity(partialUserRecord.getCity());
                profile.setState(partialUserRecord.getState());
                profile.setCountry(partialUserRecord.getCountry());
                profile.setPostalCode(partialUserRecord.getPostalCode());
                profile.update(db);
            }
        }
    }
}

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

/**
 * Saves a castle guard directly to the database.<BR>
 * There are no restrictions for the NPC, however, it will be saved
 * as a NPC guard (not a mercenary).//  w  w  w. j a v  a  2 s  .c o m
 * @param gm Game Master (player)
 * @param npc any NPC's ID
 */
public final void addAnyGuard(L2Player gm, int npc, int respawn) {
    Castle c = CastleManager.getInstance().getCastle(gm);
    if (c == null) {
        gm.sendMessage("You must be on a castle's ground.");
        return;
    }
    Connection con = null;
    try {
        con = L2DatabaseFactory.getInstance().getConnection(con);
        PreparedStatement ps = con.prepareStatement(ADD_NPC_GUARD);
        ps.setInt(1, c.getCastleId());
        ps.setInt(2, npc);
        ps.setInt(3, gm.getX());
        ps.setInt(4, gm.getY());
        ps.setInt(5, gm.getZ());
        ps.setInt(6, gm.getHeading());
        ps.setInt(7, respawn);
        ps.executeUpdate();
        ps.close();
    } catch (Exception e) {
        _log.warn("Error adding siege guard for castle " + getCastle().getName(), e);
        gm.sendMessage("Failed! Reason: " + e.getMessage());
    } finally {
        L2DatabaseFactory.close(con);
    }
}