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.l2jfree.gameserver.model.entity.GrandBossState.java
public void save() { Connection con = null;/* ww w .j a va 2s .com*/ try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement = con.prepareStatement( "INSERT INTO grandboss_intervallist (bossId,respawnDate,state) VALUES(?,?,?)"); statement.setInt(1, _bossId); statement.setLong(2, _respawnDate); statement.setInt(3, _state.ordinal()); statement.execute(); statement.close(); } catch (Exception e) { _log.error(e.getMessage(), e); } finally { L2DatabaseFactory.close(con); } }
From source file:com.spend.spendService.SearchText.java
private void Search() { try {//from w ww . j a v a 2s . com TimerTask timertask = new TimerTask() { public void run() { try { String[] seList = getSearchEngineNamesArray(); /* get search queries from keywords table */ PreparedStatement psmt = con.prepareStatement("SELECT searchKeyword FROM keywords"); ResultSet rs = psmt.executeQuery(); while (rs.next()) { searchQuery = rs.getString("searchKeyword"); /* insert search queries into searchqueue table */ for (Object se : seList) { PreparedStatement psmt1 = con.prepareStatement( "INSERT INTO searchqueue(searchText,disabled,searchEngineName) VALUES(?,0,?);"); psmt1.setString(1, searchQuery); psmt1.setString(2, se.toString()); psmt1.executeUpdate(); psmt1.close(); } } } catch (Exception ex) { System.out.println("SearchText.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 time and date timer.schedule(timertask, date, 1000 * 60 * 60 * 24); // for 24 hour 1000*60*60*24 } catch (Exception ex) { System.out.println("SearchText.java Search function ERROR " + ex.getMessage()); } }
From source file:edu.lternet.pasta.portal.user.SavedData.java
/** * Remove all data packages (i.e. all docids) from the saved data for this user. *///from w w w . jav a 2s . c o m public void removeAllDataPackages() { Connection conn = databaseClient.getConnection(); if (conn != null) { if (uid != null) { String updateSQL = String.format("DELETE FROM %s WHERE user_id=?", TABLE_NAME); logger.debug("DELETE statement: " + updateSQL); try { PreparedStatement pstmt = conn.prepareStatement(updateSQL); pstmt.setString(1, uid); 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.l2jfree.gameserver.model.entity.GrandBossState.java
public void update() { Connection con = null;//from w w w.ja v a2 s .c o m try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement = con.prepareStatement( "UPDATE grandboss_intervallist SET respawnDate = ?,state = ? WHERE bossId = ?"); statement.setLong(1, _respawnDate); statement.setInt(2, _state.ordinal()); statement.setInt(3, _bossId); statement.execute(); statement.close(); _log.info("update GrandBossState : ID-" + _bossId + ",RespawnDate-" + _respawnDate + ",State-" + _state.toString()); } catch (Exception e) { _log.warn("Exeption on update GrandBossState : ID-" + _bossId + ",RespawnDate-" + _respawnDate + ",State-" + _state.toString(), e); } finally { L2DatabaseFactory.close(con); } }
From source file:de.ingrid.importer.udk.strategy.v30.IDCStrategy3_0_0_fixFreeEntry.java
/** Read value of syslist entry from database ! * @param listId id of syslist//from w ww . j a v a 2 s. c o m * @param entryId id of antry * @param language language of entry * @return returns null if not found * @throws Exception */ protected String readSyslistValue(int listId, int entryId, String language) throws Exception { String retValue = null; sqlStr = "SELECT name FROM sys_list WHERE lst_id = ? and entry_id = ? and lang_id = ?"; PreparedStatement ps = jdbc.prepareStatement(sqlStr); ps.setInt(1, listId); ps.setInt(2, entryId); ps.setString(3, language); ResultSet rs = ps.executeQuery(); while (rs.next()) { retValue = rs.getString("name"); } rs.close(); ps.close(); return retValue; }
From source file:com.hangum.tadpole.db.bander.cubrid.CubridExecutePlanUtils.java
/** * cubrid execute plan//from w ww. j a va 2s .c o m * * @param userDB * @param sql * @return * @throws Exception */ public static String plan(UserDBDAO userDB, String sql) throws Exception { if (!sql.toLowerCase().startsWith("select")) { logger.error("[cubrid execute plan ]" + sql); throw new Exception("This statment not select. please check."); } Connection conn = null; ResultSet rs = null; PreparedStatement pstmt = null; try { // Class.forName("cubrid.jdbc.driver.CUBRIDDriver"); // conn = DriverManager.getConnection(userDB.getUrl(), userDB.getUsers(), userDB.getPasswd()); // conn.setAutoCommit(false); // auto commit? false . conn = TadpoleSQLManager.getInstance(userDB).getDataSource().getConnection(); conn.setAutoCommit(false); // auto commit? false . sql = StringUtils.trim(sql).substring(6); if (logger.isDebugEnabled()) logger.debug("[qubrid modifying query]" + sql); sql = "select " + RECOMPILE + sql; pstmt = conn.prepareStatement(sql); ((CUBRIDStatement) pstmt).setQueryInfo(true); rs = pstmt.executeQuery(); String plan = ((CUBRIDStatement) pstmt).getQueryplan(); // ? . // conn.commit(); if (logger.isDebugEnabled()) logger.debug("cubrid plan text : " + plan); return plan; } finally { if (rs != null) rs.close(); if (pstmt != null) pstmt.close(); if (conn != null) conn.close(); } }
From source file:com.l2jfree.gameserver.datatables.CharNameTable.java
private CharNameTable() { Connection con = null;//w w w .java 2 s. c om try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con .prepareStatement("SELECT charId, account_name, char_name FROM characters"); ResultSet rset = statement.executeQuery(); while (rset.next()) update(rset.getInt("charId"), rset.getString("account_name"), rset.getString("char_name")); rset.close(); statement.close(); } catch (SQLException e) { _log.warn("", e); } finally { L2DatabaseFactory.close(con); } _log.info("CharNameTable: Loaded " + _mapByObjectId.size() + " character names."); }
From source file:com.l2jfree.gameserver.instancemanager.AuctionManager.java
private final void load() { Connection con = null;//from ww w . j a v a 2 s . co m try { PreparedStatement statement; ResultSet rs; con = L2DatabaseFactory.getInstance().getConnection(con); statement = con.prepareStatement("SELECT id FROM auction ORDER BY id"); rs = statement.executeQuery(); while (rs.next()) _auctions.add(new Auction(rs.getInt("id"))); statement.close(); _log.info("AuctionManager: loaded " + getAuctions().size() + " auction(s)"); } catch (SQLException e) { _log.fatal("Exception: AuctionManager.load(): " + e.getMessage(), e); } finally { L2DatabaseFactory.close(con); } }
From source file:de.langmi.spring.batch.examples.readers.support.CompositeCursorItemReaderTest.java
/** * Create a table and fill with some test data. * * @param dataSource/*from w w w . j a va2s . c o m*/ * @throws Exception */ private void createTableWithTestData(final DataSource dataSource) throws Exception { // create table Connection conn = dataSource.getConnection(); Statement st = conn.createStatement(); st.execute(CREATE_TEST_TABLE); conn.commit(); st.close(); conn.close(); // fill with values conn = dataSource.getConnection(); // prevent auto commit for batching conn.setAutoCommit(false); PreparedStatement ps = conn.prepareStatement(INSERT); // fill with values for (int i = 0; i < EXPECTED_COUNT; i++) { ps.setString(1, String.valueOf(i)); ps.addBatch(); } ps.executeBatch(); conn.commit(); ps.close(); conn.close(); }
From source file:com.l2jfree.gameserver.instancemanager.InstanceManager.java
public void deleteInstanceTime(int playerObjId, int id) { Connection con = null;//from www . j a v a 2 s .c om try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = null; statement = con.prepareStatement(DELETE_INSTANCE_TIME); statement.setInt(1, playerObjId); statement.setInt(2, id); statement.execute(); statement.close(); _playerInstanceTimes.get(playerObjId).remove(id); } catch (Exception e) { _log.warn("Could not delete character instance time data: ", e); } finally { L2DatabaseFactory.close(con); } }