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:database.HashTablesTools.java
private static void insertIntoFailureTable(Connection connexion, String tableFailureName, String hash, String fourLetterCode) {/*from ww w . j a v a2s.c om*/ try { String insertTableSQL = "INSERT INTO " + tableFailureName + " " + "(pdbfilehash, fourLettercode) VALUES" + "(?,?)"; PreparedStatement preparedStatement = connexion.prepareStatement(insertTableSQL); preparedStatement.setString(1, hash); preparedStatement.setString(2, String.valueOf(fourLetterCode)); int ok = preparedStatement.executeUpdate(); preparedStatement.close(); System.out.println(ok + " raw created in failure table" + String.valueOf(fourLetterCode)); } catch (SQLException e1) { System.out.println("Failed to enter entry in " + tableFailureName + " table "); } }
From source file:com.useekm.indexing.postgis.IndexedStatement.java
/** * Search for indexed statements./*from w w w. j av a 2 s. co m*/ * * @return A closable iterator to the found results. */ static CloseableIterator<IndexedStatement> find(Connection conn, String table, Resource subject, URI predicate, Value object) throws SQLException, IndexException { if (subject instanceof BNode || object instanceof BNode) // BNodes are not indexed, so there is no result: return EMPTY; String sql = createQuery(SELECT + table, subject, predicate, object); StatementIterator result = null; PreparedStatement stat = conn.prepareStatement(sql); try { addBindings(stat, subject, predicate, object); result = new StatementIterator(stat); } finally { if (result == null) // else StatementIterator should close the stat stat.close(); } return result; }
From source file:com.concursive.connect.web.modules.login.utils.UserUtils.java
private static boolean updateProfileProjectId(Connection db, User user, Project project) throws SQLException { PreparedStatement pst = db .prepareStatement("UPDATE users " + "SET profile_project_id = ? " + "WHERE user_id = ? "); int i = 0;//from w ww . j av a 2 s. c om pst.setInt(++i, project.getId()); pst.setInt(++i, user.getId()); int count = pst.executeUpdate(); pst.close(); // Relate the two objects user.setProfileProjectId(project.getId()); CacheUtils.invalidateValue(Constants.SYSTEM_USER_CACHE, user.getId()); return count == 1; }
From source file:com.concursive.connect.web.modules.login.utils.UserUtils.java
public static boolean detachProfile(Connection db, int projectId) throws SQLException { PreparedStatement pst = db.prepareStatement( "UPDATE users " + "SET profile_project_id = ? " + "WHERE profile_project_id = ? "); int i = 0;// w w w. j a v a 2 s. c o m DatabaseUtils.setInt(pst, ++i, -1); pst.setInt(++i, projectId); int count = pst.executeUpdate(); pst.close(); return count == 1; }
From source file:com.concursive.connect.web.webdav.WebdavManager.java
public static int validateUser(Connection db, HttpServletRequest req) throws Exception { String argHeader = req.getHeader("Authorization"); HashMap params = getAuthenticationParams(argHeader); String username = (String) params.get("username"); if (md5Helper == null) { md5Helper = MessageDigest.getInstance("MD5"); }/*from ww w .jav a 2s .c om*/ int userId = -1; String password = null; PreparedStatement pst = db.prepareStatement( "SELECT user_id, webdav_password " + "FROM users " + "WHERE username = ? " + "AND enabled = ? "); pst.setString(1, username); pst.setBoolean(2, true); ResultSet rs = pst.executeQuery(); if (rs.next()) { userId = rs.getInt("user_id"); password = rs.getString("webdav_password"); } rs.close(); pst.close(); if (userId == -1) { return userId; } String method = req.getMethod(); String uri = (String) params.get("uri"); String a2 = MD5Encoder.encode(md5Helper.digest((method + ":" + uri).getBytes())); String digest = MD5Encoder .encode(md5Helper.digest((password + ":" + params.get("nonce") + ":" + a2).getBytes())); if (!digest.equals(params.get("response"))) { userId = -1; } return userId; }
From source file:at.becast.youploader.database.SQLite.java
public static Boolean updateUploadData(Video data, VideoMetadata metadata, int id) throws SQLException, IOException { PreparedStatement prest = null; ObjectMapper mapper = new ObjectMapper(); String sql = "UPDATE `uploads` SET `data`=?,`metadata`=? WHERE `id`=?"; prest = c.prepareStatement(sql);/*from w ww.j a v a2s . c om*/ prest.setString(1, mapper.writeValueAsString(data)); prest.setString(2, mapper.writeValueAsString(metadata)); prest.setInt(3, id); boolean res = prest.execute(); prest.close(); return res; }
From source file:com.concursive.connect.web.modules.common.social.rating.dao.Rating.java
public static int queryUserRating(Connection db, int userId, int objectId, String table, String uniqueField) throws SQLException { int existingVote = -1; PreparedStatement pst = db.prepareStatement( "SELECT rating FROM " + table + "_rating WHERE " + uniqueField + " = ? AND enteredby = ? "); pst.setInt(1, objectId);//from ww w . j a va 2 s . c o m pst.setInt(2, userId); ResultSet rs = pst.executeQuery(); if (rs.next()) { existingVote = rs.getInt("rating"); } rs.close(); pst.close(); return existingVote; }
From source file:at.becast.youploader.database.SQLite.java
public static Boolean updateUpload(int account, File file, Video data, String enddir, VideoMetadata metadata, int id) throws SQLException, IOException { PreparedStatement prest = null; String sql = "UPDATE `uploads` SET `account`=?, `file`=?, `lenght`=?, `enddir`=? WHERE `id`=?"; prest = c.prepareStatement(sql);//from w ww.j a v a 2s . c o m prest.setInt(1, account); prest.setString(2, file.getAbsolutePath()); prest.setLong(3, file.length()); prest.setString(4, enddir); prest.setInt(5, id); boolean res = prest.execute(); prest.close(); boolean upd = updateUploadData(data, metadata, id); return res && upd; }
From source file:at.becast.youploader.database.SQLite.java
public static Boolean prepareUpload(int id, String Url, String yt_id) { PreparedStatement prest = null; String sql = "UPDATE `uploads` SET `status`=?,`url`=?,`yt_id`=? WHERE `id`=?"; try {/*from w w w .ja va 2s. c o m*/ prest = c.prepareStatement(sql); prest.setString(1, UploadManager.Status.PREPARED.toString()); prest.setString(2, Url); prest.setString(3, yt_id); prest.setInt(4, id); boolean res = prest.execute(); prest.close(); return res; } catch (SQLException e) { LOG.error("Error preparing upload", e); return false; } }
From source file:edu.lafayette.metadb.model.userman.UserManDAO.java
/** * Update the password of a user.//from www . j a v a 2 s. c o m * * @param userName The username of the user to update. * @param newPassword The new password for the user to update. * @return true if the user's password is updated successfully, false otherwise */ public static boolean updatePassword(String userName, String newPassword) { Connection conn = Conn.initialize(); // Establish connection if (conn != null) { try { PreparedStatement updateUser = conn.prepareStatement(UPDATE_USER_PASSWORD); newPassword = encryptPassword(newPassword); updateUser.setString(1, newPassword); updateUser.setString(2, userName); updateUser.executeUpdate(); updateUser.close(); conn.close(); // Close statement and connection return true; } catch (Exception e) { MetaDbHelper.logEvent(e); } } return false; }