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.alibaba.druid.benckmark.pool.Oracle_Case0.java
private void p0(DataSource dataSource, String name) throws SQLException { long startMillis = System.currentTimeMillis(); long startYGC = TestUtil.getYoungGC(); long startFullGC = TestUtil.getFullGC(); final int COUNT = 1000 * 1; for (int i = 0; i < COUNT; ++i) { Connection conn = dataSource.getConnection(); PreparedStatement stmt = conn.prepareStatement("SELECT 1 FROM DUAL"); ResultSet rs = stmt.executeQuery(); rs.next();/*from w ww . j a v a2 s . c o m*/ rs.close(); stmt.close(); conn.close(); } long millis = System.currentTimeMillis() - startMillis; long ygc = TestUtil.getYoungGC() - startYGC; long fullGC = TestUtil.getFullGC() - startFullGC; System.out.println(name + " millis : " + NumberFormat.getInstance().format(millis) + ", YGC " + ygc + " FGC " + fullGC); }
From source file:com.l2jfree.gameserver.handler.admincommands.AdminRepairChar.java
private void handleRepair(String command, L2Player activeChar) { String[] parts = command.split(" "); if (parts.length != 2) return;//from ww w .ja v a2 s . c om final Integer objId = CharNameTable.getInstance().getByName(parts[1]); if (objId == 0) return; Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con .prepareStatement("UPDATE characters SET x=17867, y=170259, z=-3450 WHERE charId=?"); statement.setInt(1, objId); statement.execute(); statement.close(); statement = con.prepareStatement("DELETE FROM character_shortcuts WHERE charId=?"); statement.setInt(1, objId); statement.execute(); statement.close(); statement = con .prepareStatement("UPDATE items SET loc=\"INVENTORY\" WHERE owner_id=? AND loc=\"PAPERDOLL\""); statement.setInt(1, objId); statement.execute(); statement.close(); activeChar.sendMessage("Character " + parts[1] + " got repaired."); } catch (Exception e) { _log.warn("Could not repair character: ", e); } finally { L2DatabaseFactory.close(con); } }
From source file:adept.kbapi.sql.QuickJDBC.java
/** * retrieve connection instance/*from w w w . j a v a2 s . co m*/ */ public Connection getConnection() throws SQLException { Connection connection = connectionPool.getConnection(); if (defaultSchema != null) { PreparedStatement setSearchPathPreparedStmt = connection .prepareStatement("SET search_path TO " + defaultSchema); setSearchPathPreparedStmt.executeUpdate(); setSearchPathPreparedStmt.close(); } return connection; }
From source file:javasnack.flywaydb.FlywaydbDemo1Test.java
@BeforeTest public void prepareDb() throws Exception { Class.forName("org.h2.Driver"); conn = DriverManager.getConnection("jdbc:h2:mem:flywaydb_demo1", "sa", ""); // create test table. PreparedStatement ps = conn .prepareStatement("create table t1(id integer auto_increment primary key, name varchar, age int)"); ps.execute();//from www .j av a2 s .com ps.close(); }
From source file:com.l2jfree.gameserver.instancemanager.ItemsOnGroundManager.java
public void emptyTable() { Connection con = null;//from www . j a va 2 s . c o m try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement del = con.prepareStatement("DELETE from itemsonground"); del.execute(); del.close(); } catch (Exception e1) { _log.fatal("error while cleaning table ItemsOnGround " + e1, e1); } finally { L2DatabaseFactory.close(con); } }
From source file:net.sf.jdbcwrappers.nulltype.NullTypeTest.java
@Test public void testSetNull() throws SQLException { Connection connection = dataSource.getConnection(); try {// ww w . jav a 2 s .com PreparedStatement statement = connection.prepareStatement("UPDATE TEST SET CHAR_COL=?"); try { statement.setNull(1, Types.NULL); statement.executeUpdate(); } finally { statement.close(); } } finally { connection.close(); } }
From source file:net.sf.jdbcwrappers.nulltype.NullTypeTest.java
@Test(expected = SQLException.class) public void crossCheckDerbyBehaviour() throws SQLException { Connection rawConnection = rawDataSource.getConnection(); try {/*from w w w. j av a 2 s. c o m*/ PreparedStatement statement = rawConnection.prepareStatement("UPDATE TEST SET CHAR_COL=?"); try { statement.setNull(1, Types.NULL); statement.executeUpdate(); } finally { statement.close(); } } finally { rawConnection.close(); } }
From source file:com.l2jfree.gameserver.instancemanager.BlockListManager.java
public synchronized void remove(L2Player listOwner, String name) { Connection con = null;//from www . ja v a 2 s .co m try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con.prepareStatement(DELETE_QUERY); statement.setInt(1, listOwner.getObjectId()); statement.setString(2, name); statement.execute(); statement.close(); } catch (SQLException e) { _log.warn("", e); } finally { L2DatabaseFactory.close(con); } }
From source file:com.l2jfree.gameserver.datatables.RecordTable.java
public synchronized void update() { final int onlinePlayerCount = L2World.getInstance().getAllPlayersCount(); if (_record < onlinePlayerCount) { Connection con = null;/*from ww w . j a va2s . c o m*/ try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con .prepareStatement("INSERT INTO record (maxplayer, date) VALUES (?, NOW())"); statement.setInt(1, onlinePlayerCount); statement.execute(); statement.close(); } catch (Exception e) { _log.warn("", e); } finally { L2DatabaseFactory.close(con); } load(); } }
From source file:ca.phon.ipadictionary.impl.DatabaseDictionary.java
private void checkLangId(Connection conn) throws SQLException { final String checkSQL = "SELECT * FROM language WHERE langId = ?"; final PreparedStatement checkSt = conn.prepareStatement(checkSQL); checkSt.setString(1, getLanguage().toString()); final ResultSet checkRs = checkSt.executeQuery(); if (!checkRs.next()) { final String insertSQL = "INSERT INTO language (langId) VALUES ( ? )"; final PreparedStatement insertSt = conn.prepareStatement(insertSQL); insertSt.setString(1, getLanguage().toString()); insertSt.execute();//from ww w . ja v a2s .c o m insertSt.close(); } checkSt.close(); }