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.network.L2Client.java
public static void deleteCharByObjId(int objid) { if (objid < 0) return;// w w w . j a v a2 s .c om Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement; for (ItemRelatedTable table : TableOptimizer.getItemRelatedTables()) { statement = con.prepareStatement(table.getDeleteQuery()); statement.setInt(1, objid); statement.execute(); statement.close(); } for (CharacterRelatedTable table : TableOptimizer.getCharacterRelatedTables()) { statement = con.prepareStatement(table.getDeleteQuery()); statement.setInt(1, objid); statement.execute(); statement.close(); } statement = con.prepareStatement("DELETE FROM items WHERE owner_id=?"); statement.setInt(1, objid); statement.execute(); statement.close(); statement = con.prepareStatement("DELETE FROM characters WHERE charId=?"); statement.setInt(1, objid); statement.execute(); statement.close(); } catch (Exception e) { _log.error("Error deleting character.", e); } finally { L2DatabaseFactory.close(con); } }
From source file:com.concursive.connect.web.modules.communications.utils.EmailUpdatesUtils.java
public static void manageQueue(Connection db, TeamMember teamMember) throws SQLException { //Determine if the member is part of any other projects and has a matching email updates preference PreparedStatement pst = db.prepareStatement("SELECT count(*) AS record_count " + "FROM project_team pt " + "WHERE pt.user_id = ? " + "AND pt.email_updates_schedule = ? "); int i = 0;/*from ww w .j a v a2s . c om*/ pst.setInt(++i, teamMember.getUserId()); pst.setInt(++i, teamMember.getEmailUpdatesSchedule()); ResultSet rs = pst.executeQuery(); int records = 0; if (rs.next()) { records = rs.getInt("record_count"); } rs.close(); pst.close(); if (records == 0) { //Delete the queue since it is no longer needed. String field = ""; int emailUpdatesSchedule = teamMember.getEmailUpdatesSchedule(); if (emailUpdatesSchedule > 0) { if (emailUpdatesSchedule == TeamMember.EMAIL_OFTEN) { field = "schedule_often"; } else if (emailUpdatesSchedule == TeamMember.EMAIL_DAILY) { field = "schedule_daily"; } else if (emailUpdatesSchedule == TeamMember.EMAIL_WEEKLY) { field = "schedule_weekly"; } else if (emailUpdatesSchedule == TeamMember.EMAIL_MONTHLY) { field = "schedule_monthly"; } i = 0; pst = db.prepareStatement( "DELETE FROM email_updates_queue " + "WHERE enteredby = ? AND " + field + " = ? "); pst.setInt(++i, teamMember.getUserId()); pst.setBoolean(++i, true); pst.executeUpdate(); pst.close(); } } }
From source file:com.useekm.indexing.postgis.IndexedStatement.java
/** * Creates and stores an indexed version of the provided statement. Only use * this function if it is safe to assume that the statement is not yet in * the database. This method is faster than * {@link #addIfNew(Connection, Resource, URI, Value, String)}, but does not * check for duplicates.// www .j av a 2 s. c o m * * @param subject * The subject, BNode subjects are not allowed. * @param predicate * The predicate * @param object * The object/value * * @return The IndexedStatement to add to the index. * * @throws IllegalArgumentException * If one of the arguments equals null or if one of the * arguments is a {@link BNode}. * @throws IndexException * @Throws SQLException */ static void add(Connection conn, String table, IndexedStatement indexedStatement) throws SQLException { PreparedStatement stat = addPrepare(conn, table); try { addNewBatch(stat, indexedStatement); int count = stat.executeUpdate(); Validate.isTrue(count == 1); } finally { stat.close(); } }
From source file:com.concursive.connect.web.webdav.WebdavManager.java
/** * Gets the webdavPassword attribute of the WebdavManager object * * @param db Description of the Parameter * @param username Description of the Parameter * @return The webdavPassword value/*from w ww .j a v a2 s . com*/ * @throws SQLException Description of the Exception */ public static String getWebdavPassword(Connection db, String username) throws SQLException { String password = ""; PreparedStatement pst = db.prepareStatement( "SELECT webdav_password " + "FROM users " + "WHERE username = ? " + "AND enabled = ? "); pst.setString(1, username); pst.setBoolean(2, true); ResultSet rs = pst.executeQuery(); if (rs.next()) { password = rs.getString("webdav_password"); } rs.close(); pst.close(); return password; }
From source file:com.dynamobi.network.DynamoNetworkUdr.java
/** * Determines status of some jar file./* w w w .j av a 2 s .c o m*/ * @return Returns one of DOWNLOADED, INSTALLED, or AVAILABLE. */ private static String getStatus(String jarFile) throws SQLException { String fn = "${FARRAGO_HOME}/plugin/" + jarFile; String outfile = FarragoProperties.instance().expandProperties(fn); File f = new File(outfile); if (f.exists()) { // Either just downloaded or installed String ret = "DOWNLOADED"; Connection conn = DriverManager.getConnection("jdbc:default:connection"); String name = jarFile.replaceAll("\\.jar", ""); String query = "SELECT name FROM localdb.sys_root.dba_jars WHERE " + "name = ? AND url IN (?,?)"; PreparedStatement ps = conn.prepareStatement(query); ps.setString(1, name); ps.setString(2, fn); ps.setString(3, "file:" + fn); ResultSet rs = ps.executeQuery(); if (rs.next()) { ret = "INSTALLED"; } rs.close(); ps.close(); return ret; } else { return "AVAILABLE"; } }
From source file:at.becast.youploader.database.SQLite.java
public static boolean failUpload(int upload_id) { PreparedStatement prest = null; String sql = "UPDATE `uploads` SET `status`=?,`uploaded`=? WHERE `id`=?"; try {//from w w w .j a v a2 s. c o m prest = c.prepareStatement(sql); prest.setString(1, UploadManager.Status.FAILED.toString()); prest.setInt(3, upload_id); boolean res = prest.execute(); prest.close(); return res; } catch (SQLException e) { LOG.error("Error marking upload as failed", e); return false; } }
From source file:module.entities.NameFinder.DB.java
/** * Update the activity log//from w ww . j ava 2s . c o m * * @param endTime * @param status_id * @param regexerId * @param obj * @throws java.sql.SQLException */ public static void UpdateLogRegexFinder(long endTime, int regexerId, JSONObject obj) throws SQLException { String updateCrawlerStatusSql = "UPDATE log.activities SET " + "end_date = ?, status_id = ?, message = ?" + "WHERE id = ?"; PreparedStatement prepUpdStatusSt = connection.prepareStatement(updateCrawlerStatusSql); prepUpdStatusSt.setTimestamp(1, new java.sql.Timestamp(endTime)); prepUpdStatusSt.setInt(2, 2); prepUpdStatusSt.setString(3, obj.toJSONString()); prepUpdStatusSt.setInt(4, regexerId); prepUpdStatusSt.executeUpdate(); prepUpdStatusSt.close(); }
From source file:edu.lafayette.metadb.model.userman.UserManDAO.java
/** * Update the login time of a user.//from ww w .j a v a2 s . com * @param userName the user name to update. * @param value the value of the login time, as a long integer. * @return true if the user's login time was updated successfully, false otherwise. */ public static boolean updateLoginTime(String userName, long value) { if (!MetaDbHelper.userExists(userName)) return false; Connection conn = Conn.initialize(); // Establish connection if (conn != null) { try { PreparedStatement updateUser = conn.prepareStatement(UPDATE_LAST_LOGIN); updateUser.setLong(1, value); updateUser.setString(2, userName); updateUser.executeUpdate(); updateUser.close(); conn.close(); // Close statement and connection return true; } catch (Exception e) { MetaDbHelper.logEvent(e); } } return false; }
From source file:edu.lafayette.metadb.model.userman.UserManDAO.java
/** * Update the user type of a user./* w w w.j a va 2 s . c om*/ * * @param userName The username of the user to update. * @param newUserType The new user type for the user to update. * @return true if the user's user type is updated successfully, false otherwise */ public static boolean updateUserType(String userName, String newUserType) { Connection conn = Conn.initialize(); // Establish connection if (conn != null) { try { PreparedStatement updateUser = conn.prepareStatement(UPDATE_USER_TYPE); updateUser.setString(1, newUserType); updateUser.setString(2, userName); updateUser.executeUpdate(); updateUser.close(); conn.close(); // Close statement and connection return true; } catch (Exception e) { MetaDbHelper.logEvent(e); } } return false; }
From source file:edu.lafayette.metadb.model.userman.UserManDAO.java
/** * Update the authentication type of a user. * //from ww w . j av a2 s .c o m * @param userName The username of the user to update. * @param newAuthType The new authentication type for the user to update. * @return true if the user's authentication type is updated successfully, false otherwise */ public static boolean updateAuthType(String userName, String newAuthType) { Connection conn = Conn.initialize(); // Establish connection if (conn != null) { try { PreparedStatement updateUser = conn.prepareStatement(UPDATE_AUTH_TYPE); updateUser.setString(1, newAuthType); updateUser.setString(2, userName); updateUser.executeUpdate(); updateUser.close(); conn.close(); // Close statement and connection return true; } catch (Exception e) { MetaDbHelper.logEvent(e); } } return false; }