Example usage for java.sql PreparedStatement executeUpdate

List of usage examples for java.sql PreparedStatement executeUpdate

Introduction

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

Prototype

int executeUpdate() throws SQLException;

Source Link

Document

Executes the SQL statement in this PreparedStatement object, which must be an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.

Usage

From source file:ch.newscron.referral.ReferralManager.java

/**
 * Given a customer id and a generated short URL, inserts these two as a new row in the ShortURL table of the database
 * @param customerId an long representing the unique customer id
 * @param shortURL a String representing the short goo.gl generated URL
 *///from w w  w .  jav  a 2s .  c o m
public static boolean insertShortURL(long customerId, String shortURL) {
    Connection connection = null;
    PreparedStatement query = null;
    try {
        connection = connect();
        query = connection.prepareStatement("INSERT IGNORE INTO ShortURL (custId, shortUrl) VALUES(?, ?)");
        query.setLong(1, customerId);
        query.setString(2, shortURL);
        int newShortURL = query.executeUpdate();
        return newShortURL == 1;
    } catch (Exception ex) {
        Logger.getLogger(ReferralManager.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        disconnect(connection, query);
    }
    return false;
}

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

/**
* ?DB?????//from   w w w . ja  v a2 s  .c  om
* @param src 
* @param conn DB??
* @throws java.sql.SQLException 
* @see libepg.util.db.AboutDB#CRATE_TABLE
* @see java.sql.Connection#createStatement() 
*/
public static synchronized void convertToTable(List<TsPacket> src, Connection conn) throws SQLException {
    Statement stmt = conn.createStatement();
    //?
    stmt.executeUpdate(AboutDB.CRATE_TABLE);
    //?PID??????
    for (TsPacket tsp : src) {
        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();
    }
}

From source file:com.l2jfree.gameserver.model.GMAudit.java

public static void auditGMAction(String gm_name, String target, String type, String action, String param) {
    if (Config.GM_AUDIT) {
        Connection con = null;/* ww w  .  j  a  v  a2  s .co m*/
        try {
            con = L2DatabaseFactory.getInstance().getConnection(con);
            PreparedStatement statement = con.prepareStatement(
                    "INSERT INTO gm_audit(gm_name, target, type, action, param, date) VALUES(?,?,?,?,?,now())");

            statement.setString(1, gm_name);
            statement.setString(2, target);
            statement.setString(3, type);
            statement.setString(4, action);
            statement.setString(5, param);

            statement.executeUpdate();
        } catch (Exception e) {
            _log.fatal("", e);
        } finally {
            L2DatabaseFactory.close(con);
        }
    }
}

From source file:com.sql.Audit.java

/**
 * Adds an entry to the audit table//w ww.  j  av a2s .co m
 * @param action performed action to be stored
 */
public static void addAuditEntry(String action) {
    Connection conn = null;
    PreparedStatement ps = null;
    try {

        conn = DBConnection.connectToDB();

        String sql = "INSERT INTO Audit VALUES" + "(?,?,?)";

        ps = conn.prepareStatement(sql);
        ps.setTimestamp(1, new Timestamp(System.currentTimeMillis()));
        ps.setInt(2, 0);
        ps.setString(3, action == null ? "MISSING ACTION" : StringUtils.left(action, 255));

        ps.executeUpdate();
    } catch (SQLException ex) {
        if (ex.getCause() instanceof SQLServerException) {
            addAuditEntry(action);
        }
    } finally {
        DbUtils.closeQuietly(conn);
        DbUtils.closeQuietly(ps);
    }
}

From source file:las.DBConnector.java

public static void insertTransactionIntoTable(Member member, Item item) throws SQLException {
    String data = "INSERT INTO TRANSACTIONS(MEMBER_ID,ITEM_ID)" + "Values (?,?)";
    PreparedStatement pt = conn.prepareStatement(data);
    pt.setInt(1, member.getID());/*w  w  w . j  a  va2s  .com*/
    pt.setInt(2, item.getItemID());
    pt.executeUpdate();
}

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

public static void addPoints(L2Player player, int bossId, int points) {
    final Map<Integer, Integer> pointsByBossId = getList(player.getObjectId());

    points += pointsByBossId.containsKey(bossId) ? pointsByBossId.get(bossId).intValue() : 0;

    pointsByBossId.put(bossId, points);/*from  w w w  . j  av  a  2  s  .  c o  m*/

    Connection con = null;
    try {
        con = L2DatabaseFactory.getInstance().getConnection();
        PreparedStatement statement;
        statement = con.prepareStatement(
                "REPLACE INTO character_raid_points (`charId`,`boss_id`,`points`) VALUES (?,?,?)");
        statement.setInt(1, player.getObjectId());
        statement.setInt(2, bossId);
        statement.setInt(3, points);
        statement.executeUpdate();
        statement.close();
    } catch (Exception e) {
        _log.fatal("could not update char raid points:", e);
    } finally {
        L2DatabaseFactory.close(con);
    }
}

From source file:las.DBConnector.java

public static void incrementAmountLeft(Item item) throws SQLException {
    String data = "UPDATE ITEMS SET AMOUNTLEFT = ? WHERE ITEM_ID = ?";
    PreparedStatement pt = conn.prepareStatement(data);
    pt.setInt(1, (item.getAmountLeft() + 1));
    pt.setInt(2, item.getItemID());/*from w w w  .  ja  v  a2 s .  c  o m*/
    pt.executeUpdate();
}

From source file:las.DBConnector.java

public static void decrementAmountLeft(Item item) throws SQLException {
    String data = "UPDATE ITEMS SET AMOUNTLEFT = ? WHERE ITEM_ID = ?";
    PreparedStatement pt = conn.prepareStatement(data);
    pt.setInt(1, (item.getAmountLeft() - 1));
    pt.setInt(2, item.getItemID());// w w  w .jav  a2s . c om
    pt.executeUpdate();
}

From source file:com.silverpeas.notation.model.RatingDAO.java

public static long deleteRatings(Connection con, ContributionRatingPK pk) throws SQLException {
    PreparedStatement prepStmt = con.prepareStatement(QUERY_DELETE_RATING);
    try {//from w w  w.jav  a 2 s . com
        prepStmt.setString(1, pk.getInstanceId());
        prepStmt.setString(2, pk.getContributionId());
        prepStmt.setString(3, pk.getContributionType());
        return prepStmt.executeUpdate();
    } finally {
        DBUtil.close(prepStmt);
    }
}

From source file:las.DBConnector.java

public static void removeTransactionFromTable(Transaction transaction) throws SQLException {
    String data = "DELETE FROM TRANSACTIONS WHERE MEMBER_ID = ?" + "AND ITEM_ID = ?";
    PreparedStatement pt = conn.prepareStatement(data);
    pt.setInt(1, transaction.getMemberID());
    pt.setInt(2, transaction.getItemID());
    pt.executeUpdate();
}