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:cn.vko.cache.dao.ha.FailoverMonitorJob.java
@Override public void run() { Future<Integer> future = executor.submit(new Callable<Integer>() { @Override/*from w ww. ja v a 2s.co m*/ public Integer call() throws Exception { Integer result = -1; for (int i = 0; i < getRecheckTimes(); i++) { Connection conn = null; try { conn = getCurrentDetectorDataSource().getConnection(); PreparedStatement pstmt = conn.prepareStatement(getDetectingSQL()); pstmt.execute(); pstmt.close(); result = 0; break; } catch (Exception e) { logger.warn("(" + (i + 1) + ") check with failure. sleep (" + getRecheckInterval() + ") for next round check."); try { TimeUnit.MILLISECONDS.sleep(getRecheckInterval()); } catch (InterruptedException e1) { logger.warn("interrupted when waiting for next round rechecking."); } continue; } finally { if (conn != null) { try { conn.close(); } catch (SQLException e) { logger.warn("failed to close checking connection:\n", e); } } } } return result; } }); try { Integer result = future.get(getDetectingRequestTimeout(), TimeUnit.MILLISECONDS); if (result == -1) { doSwap(); } } catch (InterruptedException e) { logger.warn("interrupted when getting query result in FailoverMonitorJob."); } catch (ExecutionException e) { logger.warn("exception occured when checking failover status in FailoverMonitorJob"); } catch (TimeoutException e) { logger.warn("exceed DetectingRequestTimeout threshold. Switch to standby data source."); doSwap(); } }
From source file:com.alibaba.cobar.client.datasources.ha.FailoverMonitorJob.java
public void run() { Future<Integer> future = executor.submit(new Callable<Integer>() { public Integer call() throws Exception { Integer result = -1;//from w ww .j av a 2 s . com for (int i = 0; i < getRecheckTimes(); i++) { Connection conn = null; try { conn = getCurrentDetectorDataSource().getConnection(); PreparedStatement pstmt = conn.prepareStatement(getDetectingSQL()); pstmt.execute(); if (pstmt != null) { pstmt.close(); } result = 0; break; } catch (Exception e) { logger.warn("(" + (i + 1) + ") check with failure. sleep (" + getRecheckInterval() + ") for next round check."); try { TimeUnit.MILLISECONDS.sleep(getRecheckInterval()); } catch (InterruptedException e1) { logger.warn("interrupted when waiting for next round rechecking."); } continue; } finally { if (conn != null) { try { conn.close(); } catch (SQLException e) { logger.warn("failed to close checking connection:\n", e); } } } } return result; } }); try { Integer result = future.get(getDetectingRequestTimeout(), TimeUnit.MILLISECONDS); if (result == -1) { doSwap(); } } catch (InterruptedException e) { logger.warn("interrupted when getting query result in FailoverMonitorJob."); } catch (ExecutionException e) { logger.warn("exception occured when checking failover status in FailoverMonitorJob"); } catch (TimeoutException e) { logger.warn("exceed DetectingRequestTimeout threshold. Switch to standby data source."); doSwap(); } }
From source file:com.epam.training.taranovski.spring.repository.oracle.AdminRepositoryOracle.java
/** * * @param admin// w w w. j a v a 2 s . c o m * @return */ @Override public boolean update(Admin admin) { Connection connection = null; PreparedStatement preparedStatement = null; try { connection = ds.getConnection(); preparedStatement = connection.prepareStatement(""); preparedStatement.execute(); return true; } catch (SQLException ex) { Logger.getLogger(AdminRepositoryOracle.class.getName()).error(ex); } finally { DAOUtil.close(preparedStatement); DAOUtil.close(connection); } return false; }
From source file:com.epam.training.taranovski.spring.repository.oracle.AdminRepositoryOracle.java
/** * * @param admin//from w w w. ja va 2 s . c o m * @return */ @Override public boolean delete(Admin admin) { Connection connection = null; PreparedStatement preparedStatement = null; try { connection = ds.getConnection(); preparedStatement = connection.prepareStatement(""); preparedStatement.execute(); return true; } catch (SQLException ex) { Logger.getLogger(AdminRepositoryOracle.class.getName()).error(ex); } finally { DAOUtil.close(preparedStatement); DAOUtil.close(connection); } return false; }
From source file:com.l2jfree.gameserver.instancemanager.FriendListManager.java
public synchronized boolean insert(Integer objId1, Integer objId2) { boolean modified = false; modified |= _friends.containsKey(objId1) && _friends.get(objId1).add(objId2); modified |= _friends.containsKey(objId2) && _friends.get(objId2).add(objId1); if (!modified) return false; Connection con = null;//ww w.j a va 2 s . com try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con.prepareStatement(INSERT_QUERY); statement.setInt(1, Math.min(objId1, objId2)); statement.setInt(2, Math.max(objId1, objId2)); statement.execute(); statement.close(); } catch (SQLException e) { _log.warn("", e); } finally { L2DatabaseFactory.close(con); } return true; }
From source file:mx.com.pixup.portal.dao.DisqueraDaoJdbc.java
@Override public void deleteDisquera(Disquera disquera) { Connection connection = DBConecta.getConnection(); PreparedStatement preparedStatement = null; String sql = "delete from disquera where id = ?"; try {// w w w.jav a 2 s .c o m preparedStatement = connection.prepareStatement(sql); preparedStatement.setInt(1, disquera.getId()); preparedStatement.execute(); } catch (Exception e) { Logger.getLogger(DBConecta.class.getName()).log(Level.SEVERE, null, e); } finally { if (preparedStatement != null) { try { preparedStatement.close(); } catch (Exception e) { } } if (connection != null) { try { connection.close(); } catch (Exception e) { } } } }
From source file:com.keybox.manage.db.PublicKeyDB.java
/** * inserts new public key//from w w w .j a v a 2s.c o m * * @param publicKey key object */ public static void insertPublicKey(PublicKey publicKey) { Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement( "insert into public_keys(key_nm, type, fingerprint, public_key, profile_id, user_id) values (?,?,?,?,?,?)"); 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.getUserId()); stmt.execute(); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); }
From source file:com.epam.training.taranovski.spring.repository.oracle.AdminRepositoryOracle.java
/** * * @param admin//from w ww. j a v a 2s.c o m * @return */ @Override public boolean create(Admin admin) { Connection connection = null; PreparedStatement preparedStatement = null; try { connection = ds.getConnection(); preparedStatement = connection.prepareStatement("insert into "); preparedStatement.execute(); return true; } catch (SQLException ex) { Logger.getLogger(AdminRepositoryOracle.class.getName()).error(ex); } finally { DAOUtil.close(preparedStatement); DAOUtil.close(connection); } return false; }
From source file:com.redhat.victims.database.VictimsSQL.java
/** * Remove records matching a given hash. This will cascade to all * references./*from w ww. ja v a 2s . com*/ * * @param hash * @throws SQLException */ protected void deleteRecord(Connection connection, String hash) throws SQLException { int id = selectRecordId(hash); if (id > 0) { String[] queries = new String[] { Query.DELETE_FILEHASHES, Query.DELETE_METAS, Query.DELETE_CVES, Query.DELETE_RECORD_ID }; for (String query : queries) { PreparedStatement ps = setObjects(connection, query, id); ps.execute(); ps.close(); } } }
From source file:de.iritgo.aktario.jdbc.StoreUser.java
/** * Perform the command.// ww w . j a v a2s . c om */ public void perform() { if (properties.get("id") == null) { Log.logError("persist", "StoreUser", "Missing unique id for the user to store"); return; } UserRegistry userRegistry = Server.instance().getUserRegistry(); long userId = ((Long) properties.get("id")).longValue(); User user = userRegistry.getUser(userId); if (user == null) { Log.logError("persist", "StoreUser", "Unable to find user with id " + userId); return; } JDBCManager jdbcManager = (JDBCManager) Engine.instance().getManager("persist.JDBCManager"); DataSource dataSource = jdbcManager.getDefaultDataSource(); Connection connection = null; PreparedStatement stmt = null; try { connection = dataSource.getConnection(); stmt = connection.prepareStatement("delete from IritgoUser where id=?"); stmt.setLong(1, userId); stmt.execute(); stmt.close(); String userSql = "insert into IritgoUser (id, name, password, email) " + " values (?, ?, ?, ?)"; stmt = connection.prepareStatement(userSql); stmt.setLong(1, userId); stmt.setString(2, user.getName()); stmt.setString(3, user.getPassword()); stmt.setString(4, user.getEmail()); stmt.execute(); stmt.close(); stmt = connection.prepareStatement("delete from IritgoNamedObjects where userId=?"); stmt.setLong(1, userId); stmt.execute(); stmt.close(); Log.logVerbose("persist", "StoreUser", "INSERT USER " + userId + " |" + userSql + "|"); } catch (SQLException x) { Log.logError("persist", "StoreUser", "Error while storing user with id " + userId + ": " + x); } finally { DbUtils.closeQuietly(stmt); DbUtils.closeQuietly(connection); } }