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:com.keybox.manage.db.PublicKeyDB.java
/** * updates existing public key//from w ww.j a v a 2 s.c o m * * @param publicKey key object */ public static void updatePublicKey(PublicKey publicKey) { Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement( "update public_keys set key_nm=?, type=?, fingerprint=?, public_key=?, profile_id=? where id=? and user_id=? and enabled=true"); stmt.setString(1, publicKey.getKeyNm()); stmt.setString(2, SSHUtil.getKeyType(publicKey.getPublicKey())); stmt.setString(3, SSHUtil.getFingerprint(publicKey.getPublicKey())); stmt.setString(4, publicKey.getPublicKey().trim()); if (publicKey.getProfile() == null || publicKey.getProfile().getId() == null) { stmt.setNull(5, Types.NULL); } else { stmt.setLong(5, publicKey.getProfile().getId()); } stmt.setLong(6, publicKey.getId()); stmt.setLong(7, publicKey.getUserId()); stmt.execute(); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); }
From source file:com.l2jfree.gameserver.model.entity.faction.Faction.java
private void updateDB() { Connection con = null;/* w w w . j a v a2s.c o m*/ try { PreparedStatement statement; con = L2DatabaseFactory.getInstance().getConnection(con); statement = con.prepareStatement("update factions set points = ? where id = ?"); statement.setFloat(1, _points); statement.setInt(2, _Id); statement.execute(); statement.close(); } catch (Exception e) { _log.warn("Exception: Faction.load(): " + e.getMessage(), e); } finally { L2DatabaseFactory.close(con); } }
From source file:de.unidue.inf.is.ezdl.dlservices.repository.store.repositories.DBRepository.java
@Override public void removeDocument(String oid) { Connection con = null;//from w ww .ja va 2 s . c o m PreparedStatement st = null; try { con = provider.connection(); st = con.prepareStatement(REMOVE); st.setString(1, databaseIdForOid(oid)); st.execute(); con.commit(); } catch (SQLException e) { rollback(con); getLogger().error("Error removing " + databaseIdForOid(oid), e); } finally { ClosingUtils.close(st); ClosingUtils.close(con); } }
From source file:com.splicemachine.derby.test.framework.SpliceUserWatcher.java
public void createUser(String userName, String password) { Connection connection = null; PreparedStatement statement = null; try {// w w w . ja v a2s .c o m connection = SpliceNetConnection.getConnection(); statement = connection.prepareStatement("call syscs_util.syscs_create_user(?,?)"); statement.setString(1, userName); statement.setString(2, password); statement.execute(); } catch (Exception e) { LOG.error("error Creating " + e.getMessage()); e.printStackTrace(); throw new RuntimeException(e); } finally { DbUtils.closeQuietly(statement); DbUtils.commitAndCloseQuietly(connection); } }
From source file:com.l2jfree.gameserver.model.MacroList.java
/** * @param shortcut//from w w w.j a v a 2 s .c o m */ private void deleteMacroFromDb(L2Macro macro) { Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement = con .prepareStatement("DELETE FROM character_macroses WHERE charId=? AND id=?"); statement.setInt(1, _owner.getObjectId()); statement.setInt(2, macro.id); statement.execute(); statement.close(); } catch (Exception e) { _log.warn("could not delete macro:", e); } finally { L2DatabaseFactory.close(con); } }
From source file:lineage2.gameserver.dao.CharacterDAO.java
/** * Method deleteCharByObjId.//from w w w . j a va 2s . c om * @param objid int */ public void deleteCharByObjId(int objid) { if (objid < 0) { return; } Connection con = null; PreparedStatement statement = null; try { con = DatabaseFactory.getInstance().getConnection(); statement = con.prepareStatement("DELETE FROM characters WHERE obj_Id=?"); statement.setInt(1, objid); statement.execute(); } catch (Exception e) { _log.error("", e); } finally { DbUtils.closeQuietly(con, statement); } }
From source file:com.wso2telco.dep.verificationhandler.verifier.DatabaseUtils.java
/** * Write subscription./*from ww w. j a v a 2 s . com*/ * * @param userID the user id * @param application the application * @param api the api * @throws SQLException the SQL exception * @throws NamingException the naming exception */ public static void writeSubscription(String userID, String application, String api) throws SQLException, NamingException { Connection connection = null; PreparedStatement ps = null; ResultSet results = null; String sql = "INSERT INTO `dialg_stats`.`subscriptioncount` (`api`, `subscriptionCount`, `userId`, `applicationName`) VALUES (?, ?, ?, ?);"; try { try { connection = getStatsDBConnection(); } catch (NamingException ex) { Logger.getLogger(DatabaseUtils.class.getName()).log(Level.SEVERE, null, ex); } ps = connection.prepareStatement(sql); ps.setString(1, api); ps.setString(2, "1"); ps.setString(3, userID); ps.setString(4, application); ps.execute(); } catch (SQLException e) { //handleException("Error occurred while getting Invocation count for Application", e); } finally { APIMgtDBUtil.closeAllConnections(ps, connection, results); } }
From source file:com.sap.dirigible.repository.ext.db.DBUtils.java
/** * Execute a SQL script containing multiple statements separated with ';' * /*from www . j a va 2 s .c o m*/ * @param connection * @param script * @return */ public boolean executeUpdate(Connection connection, String script) { logger.debug("entering executeUpdate"); //$NON-NLS-1$ boolean status = false; StringTokenizer tokenizer = new StringTokenizer(script, SCRIPT_DELIMITER); while (tokenizer.hasMoreTokens()) { String line = tokenizer.nextToken(); if ("".equals(line.trim())) { //$NON-NLS-1$ continue; } PreparedStatement preparedStatement = null; try { preparedStatement = connection.prepareStatement(line); preparedStatement.execute(); } catch (SQLException e) { logger.error(e.getMessage()); } finally { if (preparedStatement != null) { try { preparedStatement.close(); } catch (SQLException e) { logger.error(e.getMessage()); } } } status = true; } logger.debug("exiting executeUpdate"); //$NON-NLS-1$ return status; }
From source file:com.wso2telco.dep.verificationhandler.verifier.DatabaseUtils.java
/** * Write amount./* www. jav a 2 s.c o m*/ * * @param userID the user id * @param application the application * @param amount the amount * @param msisdn the msisdn * @throws SQLException the SQL exception * @throws NamingException the naming exception */ public static void writeAmount(String userID, String application, String amount, String msisdn) throws SQLException, NamingException { Connection connection = null; PreparedStatement ps = null; ResultSet results = null; String sql = "INSERT INTO `dialg_stats`.`payment` (`application`, `amount`, `userID`, `MSISDN`, `Date`) VALUES (?, ?, ?, ?, CURDATE());"; try { try { connection = getStatsDBConnection(); } catch (NamingException ex) { Logger.getLogger(DatabaseUtils.class.getName()).log(Level.SEVERE, null, ex); } ps = connection.prepareStatement(sql); ps.setString(1, application); ps.setString(2, amount); ps.setString(3, userID); ps.setString(4, msisdn); ps.execute(); } catch (SQLException e) { //handleException("Error occurred while getting Invocation count for Application", e); } finally { APIMgtDBUtil.closeAllConnections(ps, connection, results); } }
From source file:de.nim.wscr.dao.MemberDAO.java
@Override public void updateMember(Member member) { try {/*from ww w . jav a 2 s .c o m*/ PreparedStatement statement = connection .prepareStatement("UPDATE db1.member SET FIRST_NAME = ?, LAST_NAME = ?, LICENSE = ?"); statement.setString(1, member.getFirstName()); statement.setString(2, member.getLastName()); statement.setBoolean(3, member.getDriverLicense()); statement.execute(); } catch (SQLException e) { throw new RuntimeException(e); } }