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.spend.spendService.DomainLearning.java
private void GetNewQuery() { try {/*from w ww .j a v a 2s . c o m*/ TimerTask timertask = new TimerTask() { public void run() { try { domainList = new ArrayList<String>(); String[] seList = getSearchEngineNamesArray(); /* get urls from seedurlraw table */ PreparedStatement psmt = con.prepareStatement("SELECT url FROM seedurlraw"); ResultSet rs = psmt.executeQuery(); String regex = "[/]"; String regex2 = "[.]"; String PLDomain; while (rs.next()) { PLDomain = rs.getString("url"); PLDomain = PLDomain.replaceAll("http://|https://", ""); Pattern p = Pattern.compile(regex); Matcher m = p.matcher(PLDomain); if (m.find()) { PLDomain = PLDomain.substring(0, m.start()); } Pattern p2 = Pattern.compile(regex2); Matcher m2 = p2.matcher(PLDomain); int count = 0; while (m2.find()) { count++; } m2 = p2.matcher(PLDomain); if (count > 1 && m2.find()) { PLDomain = PLDomain.substring(m2.end()); } //System.out.println(PLDomain); if (!domainList.contains(PLDomain)) { domainList.add(PLDomain); newQuery = "sparql endpoint site:" + PLDomain; for (Object se : seList) { PreparedStatement psmt1 = con.prepareStatement( "INSERT INTO searchqueue(searchText,disabled,searchEngineName) VALUES(?,0,?);"); psmt1.setString(1, newQuery); psmt1.setString(2, se.toString()); psmt1.executeUpdate(); psmt1.close(); } } } } catch (Exception ex) { System.out .println("DomainLearning.java timertask run function SQL ERROR " + ex.getMessage()); } } }; Timer timer = new Timer(); DateFormat dateformat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); Date date = dateformat.parse("20-07-2017 00:00:00"); // set date and time timer.schedule(timertask, date, 1000 * 60 * 60 * 24 * 7); // for a week 1000*60*60*24*7 } catch (Exception ex) { System.out.println("DomainLearning.java GetNewQuery function ERROR " + ex.getMessage()); } }
From source file:com.l2jfree.gameserver.instancemanager.CoupleManager.java
private final void load() { Connection con = null;/* ww w .j a v a 2 s .c om*/ try { PreparedStatement statement; ResultSet rs; con = L2DatabaseFactory.getInstance().getConnection(con); statement = con.prepareStatement("Select id from couples order by id"); rs = statement.executeQuery(); while (rs.next()) { getCouples().add(new Couple(rs.getInt("id"))); } statement.close(); _log.info("CoupleManager: loaded " + getCouples().size() + " couples(s)"); } catch (Exception e) { _log.error("Exception: CoupleManager.load(): " + e.getMessage(), e); } finally { L2DatabaseFactory.close(con); } }
From source file:com.l2jfree.gameserver.model.ShortCuts.java
public synchronized void deleteShortCut(int slot, int page) { L2ShortCut old = _shortCuts.remove(slot + page * 12); if (old == null) return;// w w w .j a v a 2 s. c o m Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement = con.prepareStatement( "DELETE FROM character_shortcuts WHERE charId=? AND slot=? AND page=? AND class_index=?"); statement.setInt(1, _owner.getObjectId()); statement.setInt(2, old.getSlot()); statement.setInt(3, old.getPage()); statement.setInt(4, _owner.getClassIndex()); statement.execute(); statement.close(); } catch (Exception e) { _log.warn("", e); } finally { L2DatabaseFactory.close(con); } if (old.getType() == L2ShortCut.TYPE_ITEM) { L2ItemInstance item = _owner.getInventory().getItemByObjectId(old.getId()); if (item != null && item.getItemType() == L2EtcItemType.SHOT) _owner.getShots().removeAutoSoulShot(item.getItemId()); } _owner.sendPacket(new ShortCutInit(_owner)); for (int shotId : _owner.getShots().getAutoSoulShots()) _owner.sendPacket(new ExAutoSoulShot(shotId, 1)); }
From source file:edu.ucsb.nceas.MCTestCase.java
protected static Vector<Hashtable<String, Object>> dbSelect(String sqlStatement, String methodName) throws SQLException { Vector<Hashtable<String, Object>> resultVector = new Vector<Hashtable<String, Object>>(); DBConnectionPool connPool = DBConnectionPool.getInstance(); DBConnection dbconn = DBConnectionPool.getDBConnection(methodName); int serialNumber = dbconn.getCheckOutSerialNumber(); PreparedStatement pstmt = null; debug("Selecting from db: " + sqlStatement); pstmt = dbconn.prepareStatement(sqlStatement); pstmt.execute();//from w ww . j a v a 2s. c om ResultSet resultSet = pstmt.getResultSet(); ResultSetMetaData rsMetaData = resultSet.getMetaData(); int numColumns = rsMetaData.getColumnCount(); debug("Number of data columns: " + numColumns); while (resultSet.next()) { Hashtable<String, Object> hashTable = new Hashtable<String, Object>(); for (int i = 1; i <= numColumns; i++) { if (resultSet.getObject(i) != null) { hashTable.put(rsMetaData.getColumnName(i), resultSet.getObject(i)); } } debug("adding data row to result vector"); resultVector.add(hashTable); } resultSet.close(); pstmt.close(); DBConnectionPool.returnDBConnection(dbconn, serialNumber); return resultVector; }
From source file:com.l2jfree.gameserver.model.entity.events.VIP.java
public static void setLoc() { Connection con = null;//w w w . ja va2 s . c om try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement = con.prepareStatement( "SELECT endx,endy,endz,startx,starty,startz FROM VIPinfo WHERE teamID = " + _team); ResultSet rset = statement.executeQuery(); rset.next(); _endX = rset.getInt("endx"); _endY = rset.getInt("endy"); _endZ = rset.getInt("endz"); _startX = rset.getInt("startx"); _startY = rset.getInt("starty"); _startZ = rset.getInt("startz"); rset.close(); statement.close(); } catch (SQLException e) { _log.error("Could not check End & Start LOC for team" + _team + " got: ", e); } finally { L2DatabaseFactory.close(con); } }
From source file:edu.lternet.pasta.portal.user.SavedData.java
/** * Removes a data package from the saved data for this user. * //w ww . j a v a 2s . co m * @param scope the scope value of the data package to be removed * @param identifer the identifier value of the data package to be removed */ public void removeDocid(String scope, Integer identifier) { Connection conn = databaseClient.getConnection(); if (conn != null) { String updateSQL = String.format("DELETE FROM %s WHERE user_id=? AND scope=? AND identifier=?", TABLE_NAME); logger.debug("DELETE statement: " + updateSQL); try { PreparedStatement pstmt = conn.prepareStatement(updateSQL); pstmt.setString(1, uid); pstmt.setString(2, scope); pstmt.setInt(3, identifier); pstmt.executeUpdate(); pstmt.close(); } catch (SQLException e) { logger.error(String.format("Delete from %s failed. SQLException: %s", TABLE_NAME, e.getMessage())); } finally { databaseClient.closeConnection(conn); } } else { logger.error("Error getting connection."); } }
From source file:com.dsf.dbxtract.cdc.AppJournalDeleteTest.java
/** * Rigourous Test :-)//from www. ja va 2 s .c o m * * @throws Exception * in case of any error */ @Test(timeOut = 120000) public void testAppWithJournalDelete() throws Exception { final Config config = new Config(configFile); BasicDataSource ds = new BasicDataSource(); Source source = config.getDataSources().getSources().get(0); ds.setDriverClassName(source.getDriver()); ds.setUsername(source.getUser()); ds.setPassword(source.getPassword()); ds.setUrl(source.getConnection()); // prepara os dados Connection conn = ds.getConnection(); conn.createStatement().execute("truncate table test"); conn.createStatement().execute("truncate table j$test"); // Carrega os dados de origem PreparedStatement ps = conn.prepareStatement("insert into test (key1,key2,data) values (?,?,?)"); for (int i = 0; i < TEST_SIZE; i++) { if ((i % 100) == 0) { ps.executeBatch(); } ps.setInt(1, i); ps.setInt(2, i); ps.setInt(3, (int) Math.random() * 500); ps.addBatch(); } ps.executeBatch(); ps.close(); app = new App(config); app.start(); Assert.assertEquals(config.getHandlers().iterator().next().getStrategy(), JournalStrategy.DELETE); // Popula as tabelas de journal ps = conn.prepareStatement("insert into j$test (key1,key2) values (?,?)"); for (int i = 0; i < TEST_SIZE; i++) { if ((i % 500) == 0) { ps.executeBatch(); } ps.setInt(1, i); ps.setInt(2, i); ps.addBatch(); } ps.executeBatch(); ps.close(); while (true) { TimeUnit.MILLISECONDS.sleep(500); ResultSet rs = conn.createStatement().executeQuery("select count(*) from j$test"); if (rs.next()) { long count = rs.getLong(1); System.out.println("remaining journal rows: " + count); rs.close(); if (count == 0L) break; } } conn.close(); ds.close(); }
From source file:mupomat.controller.ObradaKorisnik.java
public void aktivirajPostojeci(Korisnik entitet) { try {//from ww w . j a v a2s. c om Connection veza = MySqlBazaPodataka.getConnection(); PreparedStatement izraz = veza.prepareStatement("update korisnik set aktivan=1 where sifra=?"); izraz.setInt(1, entitet.getSifra()); izraz.executeUpdate(); izraz.close(); veza.close(); } catch (Exception e) { // System.out.println(e.getMessage()); e.printStackTrace(); } }
From source file:mupomat.controller.ObradaKorisnik.java
@Override public void promjeniPostojeci(Korisnik entitet) { try {/*from w w w . j av a2s . c o m*/ Connection veza = MySqlBazaPodataka.getConnection(); PreparedStatement izraz = veza.prepareStatement("update korisnik set aktivan=0 where sifra=?"); izraz.setInt(1, entitet.getSifra()); izraz.executeUpdate(); izraz.close(); veza.close(); } catch (Exception e) { // System.out.println(e.getMessage()); e.printStackTrace(); } }
From source file:com.nabla.dc.server.handler.fixed_asset.UpdateAssetDisposalHandler.java
private Date getAssetAcqisitionDate(final Connection conn, int assetId) throws SQLException, ActionException { final PreparedStatement stmt = StatementFormat.prepare(conn, "SELECT acquisition_date FROM fa_asset WHERE id=?;", assetId); try {/* ww w .j av a2 s.c o m*/ final ResultSet rs = stmt.executeQuery(); try { if (!rs.next()) throw new ActionException(CommonServerErrors.RECORD_HAS_BEEN_REMOVED); return rs.getDate(1); } finally { rs.close(); } } finally { stmt.close(); } }