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:SerializeJavaObjects_MySQL.java
public static long writeJavaObject(Connection conn, Object object) throws Exception { String className = object.getClass().getName(); PreparedStatement pstmt = conn.prepareStatement(WRITE_OBJECT_SQL); // set input parameters pstmt.setString(1, className);//from w ww. jav a 2 s. c o m pstmt.setObject(2, object); pstmt.executeUpdate(); // get the generated key for the id ResultSet rs = pstmt.getGeneratedKeys(); int id = -1; if (rs.next()) { id = rs.getInt(1); } rs.close(); pstmt.close(); System.out.println("writeJavaObject: done serializing: " + className); return id; }
From source file:com.l2jfree.gameserver.util.IdFactory.java
private static void removeExpired() { int removed = 0; Connection con = null;/*ww w . java 2 s.co m*/ try { con = L2Database.getConnection(); for (String query : REMOVE_EXPIRED_QUERIES) { final PreparedStatement ps = con.prepareStatement(query); ps.setLong(1, System.currentTimeMillis()); removed += ps.executeUpdate(); ps.close(); } } catch (SQLException e) { _log.warn("", e); } finally { L2Database.close(con); } _log.info("IdFactory: Removed " + removed + " expired entries from database."); }
From source file:ips1ap101.lib.core.db.util.DB.java
public static boolean close(PreparedStatement preparedStatement) { if (preparedStatement != null) { try {//from www .j av a2 s.c om preparedStatement.close(); return true; } catch (SQLException ex) { Bitacora.logFatal(ex); } } return false; }
From source file:net.sf.sprockets.sql.Statements.java
/** * Execute the query, get the String values in the first column of the result set, and close the * statement.//from ww w . j av a 2 s .co m * * @param stmt * must already have parameters set * @return null if the result set is empty * @since 1.5.0 */ public static List<String> allStrings(PreparedStatement stmt) throws SQLException { List<String> s = null; ResultSet rs = stmt.executeQuery(); if (rs.next()) { s = new ArrayList<String>(); do { s.add(rs.getString(1)); } while (rs.next()); } stmt.close(); return s; }
From source file:com.l2jfree.gameserver.instancemanager.RaidPointsManager.java
public static void init() { _list.clear();/*w w w. j av a 2 s . c om*/ Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con.prepareStatement("SELECT * FROM character_raid_points"); ResultSet rset = statement.executeQuery(); while (rset.next()) getList(rset.getInt("charId")).put(rset.getInt("boss_id"), rset.getInt("points")); rset.close(); statement.close(); } catch (Exception e) { _log.warn("", e); } finally { L2DatabaseFactory.close(con); } }
From source file:edumsg.core.PostgresConnection.java
public static void disconnect(ResultSet rs, PreparedStatement statment, Connection conn) { if (rs != null) { try {//from w ww . j a va2 s .com rs.close(); } catch (SQLException e) { } } if (statment != null) { try { statment.close(); } catch (SQLException e) { } } if (conn != null) { try { conn.close(); } catch (SQLException e) { } } }
From source file:com.l2jfree.gameserver.datatables.PetNameTable.java
public static boolean doesPetNameExist(String name, int petNpcId) { boolean result = true; Connection con = null;//from w w w.jav a 2s . c o m try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement = con.prepareStatement( "SELECT name FROM pets p, items i WHERE p.item_obj_id = i.object_id AND name=? AND i.item_id=?"); statement.setString(1, name); statement.setString(2, Integer.toString(PetDataTable.getItemIdByPetId(petNpcId))); ResultSet rset = statement.executeQuery(); result = rset.next(); rset.close(); statement.close(); } catch (SQLException e) { _log.warn("could not check existing petname:" + e.getMessage(), e); } finally { L2DatabaseFactory.close(con); } return result; }
From source file:net.codjo.dataprocess.server.treatmenthelper.TreatmentHelper.java
public static void deleteRepository(Connection con, int repositoryId) throws SQLException { String sql = "delete PM_REPOSITORY_CONTENT where REPOSITORY_ID = ? " + " delete PM_REPOSITORY where REPOSITORY_ID = ?"; PreparedStatement pStmt = con.prepareStatement(sql); try {//from w w w . j av a2 s .com pStmt.setInt(1, repositoryId); pStmt.setInt(2, repositoryId); pStmt.executeUpdate(); } finally { pStmt.close(); } }
From source file:net.sf.sprockets.sql.Statements.java
/** * Execute the query, get the long values in the first row of the result set, and close the * statement./*from ww w. jav a 2 s .c om*/ * * @param stmt * must already have parameters set * @return null if the result set is empty * @since 1.4.0 */ public static long[] firstLongRow(PreparedStatement stmt) throws SQLException { long[] l = null; ResultSet rs = stmt.executeQuery(); if (rs.next()) { l = new long[rs.getMetaData().getColumnCount()]; for (int i = 0; i < l.length; i++) { l[i] = rs.getLong(i + 1); } } stmt.close(); return l; }
From source file:net.sf.sprockets.sql.Statements.java
/** * Execute the query, get the long values in the first column of the result set, and close the * statement.//from ww w . j a va2 s . com * * @param stmt * must already have parameters set * @return null if the result set is empty * @since 1.4.0 */ public static long[] allLongs(PreparedStatement stmt) throws SQLException { long[] l = null; ResultSet rs = stmt.executeQuery(); if (rs.next()) { LongList list = new ArrayLongList(); do { list.add(rs.getLong(1)); } while (rs.next()); l = list.toArray(); } stmt.close(); return l; }