List of usage examples for java.sql PreparedStatement close
void close() throws SQLException;
Statement
object's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed. From source file:com.concursive.connect.web.modules.documents.dao.FileItemList.java
/** * Returns the number of fileItems that match the module and itemid * * @param db Description of the Parameter * @param linkModuleId Description of the Parameter * @param linkItemId Description of the Parameter * @return Description of the Return Value * @throws SQLException Description of the Exception */// w w w .j a va 2 s. c o m public static int retrieveRecordCount(Connection db, int linkModuleId, int linkItemId) throws SQLException { int count = 0; PreparedStatement pst = db.prepareStatement("SELECT COUNT(*) as filecount " + "FROM project_files pf " + "WHERE pf.link_module_id = ? and pf.link_item_id = ? "); pst.setInt(1, linkModuleId); pst.setInt(2, linkItemId); ResultSet rs = pst.executeQuery(); if (rs.next()) { count = rs.getInt("filecount"); } rs.close(); pst.close(); return count; }
From source file:com.fileanalyzer.dao.impl.FilesDAOImpl.java
@Override public void doFinal(final Connection con, final PreparedStatement preparedStatement) { if (preparedStatement != null) { try {/*from w w w .ja v a 2 s.c o m*/ preparedStatement.close(); } catch (SQLException ex) { log.error(ex); } } try { con.setAutoCommit(true); } catch (SQLException ex) { log.error("setAutoCommit(true)", ex); } if (con != null) { try { con.close(); } catch (SQLException ex) { log.error(ex); } } }
From source file:com.l2jfree.gameserver.instancemanager.AuctionManager.java
/** Init Clan NPC aution */ public void initNPC(int id) { Connection con = null;//w w w . ja v a 2 s . co m int found = -1; for (int i = 0; i < ITEM_INIT_IDS.length; i++) { if (ITEM_INIT_IDS[i] == id) { found = i; break; } } if (found == -1) { _log.warn("Clan Hall auction not found for Id :" + id); return; } try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement; statement = con.prepareStatement("INSERT INTO `auction` VALUES " + ITEM_INIT_DATA[found]); statement.execute(); statement.close(); _auctions.add(new Auction(id)); } catch (Exception e) { _log.fatal("Exception: Auction.initNPC(): " + e.getMessage(), e); } finally { L2DatabaseFactory.close(con); } }
From source file:com.uit.anonymousidentity.Repository.Nonces.NonceJDBCTemplate.java
@Override public void store(Nonce nonce) throws SQLException { String t_sql = "insert into %s (%s, %s) values (?, ?)"; String sql = String.format(t_sql, TABLE_NAME, VALUE, SID); PreparedStatement pst = dataSource.getConnection().prepareStatement(sql); pst.setBytes(1, nonce.getByteArray()); pst.setString(2, nonce.getIssuerSid()); pst.executeUpdate();/*from w w w . j a v a 2s.co m*/ pst.close(); }
From source file:oobbit.orm.Comments.java
/** * Removes a single comment. Please note that this is not called when a Link * is removed, the database handles the deletion of associated comments by * itself via CASCADE.//from w ww .ja v a 2 s . c o m * * @param commentId * * @throws SQLException PreparedStatement failed to execute */ public void remove(int commentId) throws SQLException { PreparedStatement statement = getConnection() .prepareStatement("DELETE FROM `oobbit`.`comments` WHERE `comments`.`comment_id` = ?"); statement.setInt(1, commentId); statement.executeUpdate(); statement.close(); }
From source file:oobbit.orm.Links.java
public void remove(int linkId) throws SQLException { PreparedStatement statement = getConnection() .prepareStatement("DELETE FROM `oobbit`.`links` WHERE `links`.`link_id` = ?;"); statement.setInt(1, linkId);/*w ww .j a v a 2 s . c o m*/ statement.executeUpdate(); statement.close(); }
From source file:com.l2jfree.gameserver.idfactory.BitSetRebuildFactory.java
public synchronized void initialize() { _log.info("starting db rebuild, good luck"); _log.info("this will take a while, dont kill the process or power off youre machine!"); try {// w w w.j a v a2 s.c om _freeIds = new BitSet(PrimeFinder.nextPrime(100000)); _freeIds.clear(); _freeIdCount = new AtomicInteger(FREE_OBJECT_ID_SIZE); List<Integer> used_ids = new FastList<Integer>(); // first get all used ids for (int usedObjectId : extractUsedObjectIDTable()) used_ids.add(usedObjectId); _nextFreeId = new AtomicInteger(_freeIds.nextClearBit(0)); Connection con = null; con = L2DatabaseFactory.getInstance().getConnection(con); int nextid; int changedids = 0; // now loop through all already used oids and assign a new clean one for (int i : extractUsedObjectIDTable()) { for (;;) //danger ;) { nextid = getNextId(); if (!used_ids.contains(nextid)) break; } for (String update : ID_UPDATES) { PreparedStatement ps = con.prepareStatement(update); ps.setInt(1, nextid); ps.setInt(2, i); ps.execute(); ps.close(); changedids++; } } _log.info( "database rebuild done, changed " + changedids + " ids, set idfactory config to BitSet! ^o^/"); System.exit(0); } catch (Exception e) { _log.fatal("could not rebuild database! :", e); System.exit(0); } }
From source file:com.l2jfree.gameserver.instancemanager.BlockListManager.java
public synchronized void insert(L2Player listOwner, L2Player blocked) { Connection con = null;/*from www . j ava 2s .c om*/ try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con.prepareStatement(INSERT_QUERY); statement.setInt(1, listOwner.getObjectId()); statement.setString(2, blocked.getName()); statement.execute(); statement.close(); } catch (SQLException e) { _log.warn("", e); } finally { L2DatabaseFactory.close(con); } }
From source file:com.expedia.edw.cache.dao.GrabberDaoJDBC.java
@Override public Map<String, String> getData(String schemaAndDBname, String keyName, String valueName) { Connection conn = null;// ww w .jav a 2 s . c o m MapperDictionary mapperDictionary = new MapperDictionary(); Map<String, String> dictionary = null; PreparedStatement ps = null; try { conn = dataSource.getConnection(); ps = conn.prepareStatement("SELECT " + keyName + "," + valueName + " FROM " + schemaAndDBname); dictionary = mapperDictionary.convert(ps.executeQuery()); ps.close(); } catch (SQLException e) { logger.error(e); } finally { if (conn != null) { try { conn.close(); } catch (SQLException e) { logger.error(e); } } } return dictionary; }
From source file:com.att.pirates.controller.GlobalDataController.java
public static List<String> GetAllPRISMIDs() { List<String> apps = new ArrayList<String>(); ResultSet rs = null;//from ww w.ja v a2s . co m Connection conn = null; PreparedStatement preparedStatement = null; try { conn = DBUtility.getDBConnection(); // SQL query command String SQL = " SELECT [PRISMId] " + " FROM [Projects] "; preparedStatement = conn.prepareStatement(SQL); rs = preparedStatement.executeQuery(); while (rs.next()) { String appName = rs.getString("PRISMId"); apps.add(appName); } } catch (SQLException e) { logger.error(e.getMessage()); } catch (Exception e) { logger.error(e.getMessage()); } finally { try { if (rs != null) rs.close(); } catch (Exception e) { } ; try { if (preparedStatement != null) preparedStatement.close(); } catch (Exception e) { } ; try { if (conn != null) conn.close(); } catch (Exception e) { } ; } return apps; }