List of usage examples for java.sql PreparedStatement execute
boolean execute() throws SQLException;
PreparedStatement
object, which may be any kind of SQL statement. From source file:lineage2.gameserver.model.entity.residence.ClanHall.java
/** * Method updateOwnerInDB./*from w w w. ja va2 s . com*/ * @param clan Clan */ private void updateOwnerInDB(Clan clan) { _owner = clan; Connection con = null; PreparedStatement statement = null; try { con = DatabaseFactory.getInstance().getConnection(); statement = con.prepareStatement("UPDATE clan_data SET hasHideout=0 WHERE hasHideout=?"); statement.setInt(1, getId()); statement.execute(); DbUtils.close(statement); statement = con.prepareStatement("UPDATE clan_data SET hasHideout=? WHERE clan_id=?"); statement.setInt(1, getId()); statement.setInt(2, getOwnerId()); statement.execute(); DbUtils.close(statement); statement = con.prepareStatement("DELETE FROM residence_functions WHERE id=?"); statement.setInt(1, getId()); statement.execute(); DbUtils.close(statement); if (clan != null) { clan.setHasHideout(getId()); clan.broadcastClanStatus(false, true, false); } } catch (Exception e) { _log.warn("Exception: updateOwnerInDB(L2Clan clan): " + e, e); } finally { DbUtils.closeQuietly(con, statement); } }
From source file:com.fpmislata.banco.persistencia.impl.SucursalBancariaDAOImplJDBC.java
@Override public SucursalBancaria insert(SucursalBancaria sucursalBancaria) { Connection connection = connectionFactory.getConnection(); String SQL = "INSERT INTO sucursalbancaria VALUES(?,?,?,?)"; try {//from w ww.ja v a 2s . c om PreparedStatement preparedStatement = connection.prepareStatement(SQL); preparedStatement.setInt(1, sucursalBancaria.getId()); preparedStatement.setInt(2, sucursalBancaria.getEntidadPertenece()); preparedStatement.setString(3, sucursalBancaria.getCodigoSucursal()); preparedStatement.setString(4, sucursalBancaria.getNombreSucursal()); preparedStatement.execute(); return get(sucursalBancaria.getId()); } catch (Exception ex) { throw new RuntimeException(ex); } finally { try { connection.close(); } catch (Exception ex) { throw new RuntimeException(ex); } } }
From source file:com.fpmislata.banco.persistencia.impl.SucursalBancariaDAOImplJDBC.java
@Override public SucursalBancaria update(SucursalBancaria sucursalBancaria) { Connection connection = connectionFactory.getConnection(); String SQL = "UPDATE sucursalbancaria SET entidadPertenece=?, codigoSucursal=?, nombreSucursal=? WHERE id=?"; try {// w w w . ja v a 2 s .c o m PreparedStatement preparedStatement = connection.prepareStatement(SQL); preparedStatement.setInt(1, sucursalBancaria.getEntidadPertenece()); preparedStatement.setString(2, sucursalBancaria.getCodigoSucursal()); preparedStatement.setString(3, sucursalBancaria.getNombreSucursal()); preparedStatement.setInt(4, sucursalBancaria.getId()); preparedStatement.execute(); return get(sucursalBancaria.getId()); } catch (Exception ex) { throw new RuntimeException(ex); } finally { try { connection.close(); } catch (Exception ex) { throw new RuntimeException(ex); } } }
From source file:dk.netarkivet.harvester.datamodel.MySQLSpecifics.java
/** * Dispose of a temporary table created with getTemporaryTable. This can be * expected to be called from within a finally clause, so it mustn't throw * exceptions.// w w w . java 2s. c o m * * @param c The DB connection to use. * @param tableName The name of the temporary table */ public void dropJobConfigsTmpTable(Connection c, String tableName) { ArgumentNotValid.checkNotNull(c, "Connection c"); ArgumentNotValid.checkNotNullOrEmpty(tableName, "String tableName"); PreparedStatement s = null; try { // Now drop the temporary table s = c.prepareStatement("DROP TEMPORARY TABLE " + tableName); s.execute(); } catch (SQLException e) { log.warn("Couldn't drop temporary table " + tableName + "\n" + ExceptionUtils.getSQLExceptionCause(e), e); } }
From source file:com.wso2telco.gsma.authenticators.DBUtils.java
/** * Delete authenticate data.//from w w w .j ava 2s . c o m * * @param tokenId the token id * @throws SQLException the SQL exception */ public static void deleteAuthenticateData(String tokenId) throws SQLException { Connection connection = null; PreparedStatement ps = null; //String sql = // "DELETE FROM authenticated_login " + // "WHERE tokenID=?; " ; StringBuilder sql = new StringBuilder(); sql.append("DELETE FROM "); sql.append(TableName.AUTHENTICATED_LOGIN); sql.append(" WHERE tokenID=?"); try { try { connection = getConnectDBConnection(); } catch (AuthenticatorException e) { log.error("Delete authenticate data Error" + e); } ps = connection.prepareStatement(sql.toString()); ps.setString(1, tokenId); ps.execute(); } catch (SQLException e) { log.error("Error " + e); } finally { connection.close(); } }
From source file:com.anyuan.thomweboss.persistence.jdbcimpl.user.UserDaoJdbcImpl.java
private long saveContact(Connection conn, Contact contact) { long id = -1; String sql = "insert into t_contact(f_email, f_phoneid, f_addressid)" + " values(?, ?, ?)"; try {/* ww w .ja v a 2 s. c o m*/ PreparedStatement preState = conn.prepareStatement(sql, PreparedStatement.RETURN_GENERATED_KEYS); preState.setString(1, contact.getEmail()); preState.setLong(2, contact.getPhone().getId()); preState.setLong(3, contact.getAddress().getId()); preState.execute(); id = generateId(preState); if (-1 != id) { contact.setId(id); } } catch (SQLException e) { e.printStackTrace(); } return id; }
From source file:com.tacitknowledge.util.migration.jdbc.PatchTable.java
/** * Creates an initial record in the patches table for this system. * * @throws SQLException if an unrecoverable database error occurs * @throws MigrationException if an unrecoverable database error occurs *//* w ww. ja va 2 s. com*/ private void createSystemPatchRecord() throws MigrationException, SQLException { String systemName = context.getSystemName(); Connection conn = null; PreparedStatement stmt = null; try { conn = context.getConnection(); stmt = conn.prepareStatement(getSql("level.create")); stmt.setString(1, systemName); stmt.execute(); context.commit(); log.info("Created patch record for " + systemName); } catch (SQLException e) { log.error("Error creating patch record for system '" + systemName + "'", e); throw e; } finally { SqlUtil.close(conn, stmt, null); } }
From source file:hermes.store.schema.DefaultJDBCAdapter.java
@Override public void update(Connection connection, String id, Message message) throws SQLException, JMSException { final String messageAsXMLString = xmlHelper.toXML(message); final InputStream messageAsXML = new StringInputStream(messageAsXMLString); final PreparedStatement pstmt = connection .prepareStatement("update messages set message = ? where messageid = ?"); pstmt.setString(1, message.getJMSMessageID()); pstmt.setAsciiStream(2, messageAsXML, messageAsXMLString.length()); pstmt.execute(); pstmt.close();//from w w w. j a va 2 s. co m }
From source file:com.l2jfree.gameserver.model.entity.faction.FactionMember.java
private void updateDb() { Connection con = null;/*www.j ava 2 s .c o m*/ try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement; statement = con.prepareStatement( "UPDATE faction_members SET faction_points=?,contributions=?,faction_id=? WHERE player_id=?"); statement.setInt(1, _factionPoints); statement.setInt(2, _contributions); statement.setInt(3, _factionId); statement.setInt(4, _playerId); statement.execute(); statement.close(); } catch (Exception e) { _log.warn("Exception: FactionMember.updateDb(): " + e.getMessage(), e); } finally { L2DatabaseFactory.close(con); } }
From source file:com.microsoftopentechnologies.azchat.web.dao.UserPreferenceDAOImpl.java
/** * This method executes create User Preference table query on the azure SQL * database./* w w w . j a v a 2s. c o m*/ * * @throws Exception * @author Rupesh_shirude */ @Override public void createUserPreferenceTable() throws Exception { Connection connection = null; Connection connection1 = null; PreparedStatement preparedStatement = null; PreparedStatement preparedStatement1 = null; try { connection = AzureChatUtils.getConnection(AzureChatUtils.buildConnectionString()); preparedStatement = connection.prepareStatement(AzureChatSQLConstants.CREATE_USER_PREFERENCES_TABLE); preparedStatement.execute(); connection1 = AzureChatUtils.getConnection(AzureChatUtils.buildConnectionString()); preparedStatement1 = connection1 .prepareStatement(AzureChatSQLConstants.CREATE_USER_PREFERENCES_TABLE_INDEX); preparedStatement1.execute(); } catch (Exception e) { LOGGER.error( "Exception occurred while executing create user preference table in Azure SQL database. Exception Message : " + e.getMessage()); throw new AzureChatSystemException( "Exception occurred while executing create user preference table in Azure SQL database. Exception Message : " + e.getMessage()); } finally { AzureChatUtils.closeDatabaseResources(preparedStatement, connection); AzureChatUtils.closeDatabaseResources(preparedStatement1, connection1); } }