Example usage for java.sql PreparedStatement execute

List of usage examples for java.sql PreparedStatement execute

Introduction

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

Prototype

boolean execute() throws SQLException;

Source Link

Document

Executes the SQL statement in this PreparedStatement object, which may be any kind of SQL statement.

Usage

From source file:lineage2.gameserver.cache.CrestCache.java

/**
 * Method saveAllyCrest./*  w  ww.  j a va  2s .co m*/
 * @param pledgeId int
 * @param crest byte[]
 * @return int
 */
public int saveAllyCrest(int pledgeId, byte[] crest) {
    int crestId = getCrestId(pledgeId, crest);
    writeLock.lock();
    try {
        _allyCrestId.put(pledgeId, crestId);
        _allyCrest.put(crestId, crest);
    } finally {
        writeLock.unlock();
    }
    Connection con = null;
    PreparedStatement statement = null;
    try {
        con = DatabaseFactory.getInstance().getConnection();
        statement = con.prepareStatement("UPDATE ally_data SET crest=? WHERE ally_id=?");
        statement.setBytes(1, crest);
        statement.setInt(2, pledgeId);
        statement.execute();
    } catch (Exception e) {
        _log.error("", e);
    } finally {
        DbUtils.closeQuietly(con, statement);
    }
    return crestId;
}

From source file:lineage2.gameserver.cache.CrestCache.java

/**
 * Method savePledgeCrestLarge./* www  .j a va 2s  .  c o m*/
 * @param pledgeId int
 * @param crest byte[]
 * @return int
 */
public int savePledgeCrestLarge(int pledgeId, byte[] crest) {
    int crestId = getCrestId(pledgeId, crest);
    writeLock.lock();
    try {
        _pledgeCrestLargeId.put(pledgeId, crestId);
        get_pledgeCrestLarge().put(crestId, crest);
    } finally {
        writeLock.unlock();
    }
    Connection con = null;
    PreparedStatement statement = null;
    try {
        con = DatabaseFactory.getInstance().getConnection();
        statement = con.prepareStatement("UPDATE clan_data SET largecrest=? WHERE clan_id=?");
        statement.setBytes(1, crest);
        statement.setInt(2, pledgeId);
        statement.execute();
    } catch (Exception e) {
        _log.error("", e);
    } finally {
        DbUtils.closeQuietly(con, statement);
    }
    return crestId;
}

From source file:lineage2.gameserver.cache.CrestCache.java

/**
 * Method removePledgeCrest./*  w  ww  .j a va2  s .co  m*/
 * @param pledgeId int
 */
public void removePledgeCrest(int pledgeId) {
    writeLock.lock();
    try {
        _pledgeCrest.remove(_pledgeCrestId.remove(pledgeId));
    } finally {
        writeLock.unlock();
    }
    Connection con = null;
    PreparedStatement statement = null;
    try {
        con = DatabaseFactory.getInstance().getConnection();
        statement = con.prepareStatement("UPDATE clan_data SET crest=? WHERE clan_id=?");
        statement.setNull(1, Types.VARBINARY);
        statement.setInt(2, pledgeId);
        statement.execute();
    } catch (Exception e) {
        _log.error("", e);
    } finally {
        DbUtils.closeQuietly(con, statement);
    }
}

From source file:lineage2.gameserver.cache.CrestCache.java

/**
 * Method removeAllyCrest./*  www  .  j a v  a 2  s.c o m*/
 * @param pledgeId int
 */
public void removeAllyCrest(int pledgeId) {
    writeLock.lock();
    try {
        _allyCrest.remove(_allyCrestId.remove(pledgeId));
    } finally {
        writeLock.unlock();
    }
    Connection con = null;
    PreparedStatement statement = null;
    try {
        con = DatabaseFactory.getInstance().getConnection();
        statement = con.prepareStatement("UPDATE ally_data SET crest=? WHERE ally_id=?");
        statement.setNull(1, Types.VARBINARY);
        statement.setInt(2, pledgeId);
        statement.execute();
    } catch (Exception e) {
        _log.error("", e);
    } finally {
        DbUtils.closeQuietly(con, statement);
    }
}

From source file:com.l2jfree.gameserver.datatables.ClanTable.java

public void storeclanswars(int clanId1, int clanId2) {
    L2Clan clan1 = ClanTable.getInstance().getClan(clanId1);
    L2Clan clan2 = ClanTable.getInstance().getClan(clanId2);
    clan1.setEnemyClan(clan2);/* w w  w.  j  a  va  2  s .c  om*/
    clan2.setAttackerClan(clan1);
    clan1.broadcastClanStatus();
    clan2.broadcastClanStatus();

    Connection con = null;
    try {
        con = L2DatabaseFactory.getInstance().getConnection(con);
        PreparedStatement statement;
        statement = con.prepareStatement(
                "REPLACE INTO clan_wars (clan1, clan2, wantspeace1, wantspeace2) VALUES(?,?,?,?)");
        statement.setInt(1, clanId1);
        statement.setInt(2, clanId2);
        statement.setInt(3, 0);
        statement.setInt(4, 0);
        statement.execute();
        statement.close();
    } catch (Exception e) {
        _log.error("could not store clans wars data:", e);
    } finally {
        L2DatabaseFactory.close(con);
    }

    SystemMessage msg = new SystemMessage(SystemMessageId.CLAN_WAR_DECLARED_AGAINST_S1_IF_KILLED_LOSE_LOW_EXP);
    msg.addString(clan2.getName());
    clan1.broadcastToOnlineMembers(msg);
    msg = new SystemMessage(SystemMessageId.CLAN_S1_DECLARED_WAR);
    msg.addString(clan1.getName());
    clan2.broadcastToOnlineMembers(msg);
}

From source file:de.klemp.middleware.controller.Controller.java

/**
 * This method saves the processes, defined with the GUI, in the database.
 * //ww w . j  a  va2 s  . c om
 * @param classInput
 *            class of the first component
 * @param methodInput
 *            method of the first component
 * @param nameInput
 *            name of the input device
 * @param classOutput
 *            class of the second component
 * @param methodOutput
 *            method of the second component
 * @param data
 *            name of the data, "data fehlt" or ""
 * @param topic
 *            topic for the message broker
 */
public static synchronized void setController(String classInput, String methodInput, String nameInput,
        String classOutput, String methodOutput, String topic, String data) {
    createDBConnection();
    if (classInput != null && methodInput != null && nameInput != null && classOutput != null
            && methodOutput != null && topic != null && classInput != "" && methodInput != "" && nameInput != ""
            && classOutput != "" && methodOutput != "" && topic != "") {
        try {
            Statement st = conn.createStatement();
            PreparedStatement stp = conn.prepareStatement(
                    "insert into \"Controller\"(classInput,methodInput,nameInputDevice,classOutput,methodOutput,topic,data) values (?,?,?,?,?,?,?)");
            stp.setString(1, classInput);
            stp.setString(2, methodInput);
            stp.setString(3, nameInput);
            stp.setString(4, classOutput);
            stp.setString(5, methodOutput);
            stp.setString(6, topic);
            stp.setString(7, data);
            stp.execute();

        } catch (SQLException e) {

            String message = e.getMessage();
            if (!message.contains("doppelter Schlsselwert")) {
                logger.error("SQL Exception", e);
            }
        }
        closeDBConnection();
        controllerToList();
    }
}

From source file:com.netspective.axiom.sql.Query.java

protected QueryResultSet executeAndIgnoreStatistics(ConnectionContext cc, Object[] overrideParams,
        boolean scrollable) throws NamingException, SQLException {
    if (log.isTraceEnabled())
        trace(cc, overrideParams);//from   w w w  .j av  a 2 s  . com
    try {
        PreparedStatement stmt = createStatement(cc, overrideParams, scrollable);

        boolean executeStmtResult = stmt.execute();
        return new QueryResultSet(this, cc, executeStmtResult, stmt.getResultSet());
    } catch (SQLException e) {
        log.error(createExceptionMessage(cc, overrideParams), e);
        throw e;
    }
}

From source file:com.micromux.cassandra.jdbc.CollectionsTest.java

@Test
public void testUpdateMap() throws Exception {
    if (LOG.isDebugEnabled())
        LOG.debug("Test: 'testUpdateMap'\n");

    Statement statement = con.createStatement();

    // add some items to the set
    String update1 = "UPDATE testcollection SET M = M + {1.0: true, 3.0: false, 5.0: false} WHERE k = 1;";
    statement.executeUpdate(update1);//w ww.  j a v  a 2s .co m

    ResultSet result = statement.executeQuery("SELECT * FROM testcollection WHERE k = 1;");
    result.next();

    assertEquals(1, result.getInt("k"));
    Object myObj = result.getObject("m");
    Map<Double, Boolean> myMap = (Map<Double, Boolean>) myObj;
    assertEquals(6, myMap.size());
    assertTrue(myMap.keySet().contains(5.0));

    if (LOG.isDebugEnabled())
        LOG.debug("m           = '{}'", myObj);

    // remove an item from the map
    String update2 = "DELETE M[6.0] FROM testcollection WHERE k = 1;";
    statement.executeUpdate(update2);

    result = statement.executeQuery("SELECT * FROM testcollection WHERE k = 1;");
    result.next();

    assertEquals(1, result.getInt("k"));

    myObj = result.getObject("m");
    myMap = (Map<Double, Boolean>) myObj;
    assertEquals(5, myMap.size());
    assertTrue(myMap.keySet().contains(5.0));
    assertFalse(myMap.keySet().contains(6.0));

    if (LOG.isDebugEnabled())
        LOG.debug("m           = '{}'", myObj);

    String update4 = "UPDATE testcollection SET M =  ? WHERE k = 1;";

    PreparedStatement prepared = con.prepareStatement(update4);
    Map<Double, Boolean> myNewMap = new LinkedHashMap<Double, Boolean>();
    myNewMap.put(10.0, false);
    myNewMap.put(12.0, true);
    prepared.setObject(1, myNewMap, Types.OTHER);
    prepared.execute();

    result = prepared.executeQuery("SELECT * FROM testcollection WHERE k = 1;");
    result.next();
    myObj = result.getObject("m");
    myMap = (Map<Double, Boolean>) myObj;

    if (LOG.isDebugEnabled())
        LOG.debug("m (prepared)= '{}'\n", myObj);
}

From source file:lineage2.gameserver.cache.CrestCache.java

/**
 * Method removePledgeCrestLarge./*from   ww  w  .  j a v a 2  s.c  o  m*/
 * @param pledgeId int
 */
public void removePledgeCrestLarge(int pledgeId) {
    writeLock.lock();
    try {
        get_pledgeCrestLarge().remove(_pledgeCrestLargeId.remove(pledgeId));
    } finally {
        writeLock.unlock();
    }
    Connection con = null;
    PreparedStatement statement = null;
    try {
        con = DatabaseFactory.getInstance().getConnection();
        statement = con.prepareStatement("UPDATE clan_data SET largecrest=? WHERE clan_id=?");
        statement.setNull(1, Types.VARBINARY);
        statement.setInt(2, pledgeId);
        statement.execute();
    } catch (Exception e) {
        _log.error("", e);
    } finally {
        DbUtils.closeQuietly(con, statement);
    }
}

From source file:net.sf.l2j.gameserver.model.entity.Couple.java

public Couple(L2PcInstance player1, L2PcInstance player2) {
    int _tempPlayer1Id = player1.getObjectId();
    int _tempPlayer2Id = player2.getObjectId();
    _player1Id = _tempPlayer1Id;/*from   w  ww  . j  a  va  2  s  . c  o m*/
    _player2Id = _tempPlayer2Id;
    _affiancedDate = Calendar.getInstance();
    _affiancedDate.setTimeInMillis(Calendar.getInstance().getTimeInMillis());
    _weddingDate = Calendar.getInstance();
    _weddingDate.setTimeInMillis(Calendar.getInstance().getTimeInMillis());
    java.sql.Connection con = null;
    try {
        con = L2DatabaseFactory.getInstance().getConnection();
        PreparedStatement statement;
        _Id = IdFactory.getInstance().getNextId();
        statement = con.prepareStatement(
                "INSERT INTO couples (id, player1Id, player2Id, maried, affiancedDate, weddingDate) VALUES (?, ?, ?, ?, ?, ?)");
        statement.setInt(1, _Id);
        statement.setInt(2, _player1Id);
        statement.setInt(3, _player2Id);
        statement.setBoolean(4, false);
        statement.setLong(5, _affiancedDate.getTimeInMillis());
        statement.setLong(6, _weddingDate.getTimeInMillis());
        statement.execute();
        statement.close();
    } catch (Exception e) {
        _log.error("", e);
    } finally {
        try {
            con.close();
        } catch (Exception e) {
        }
    }
}