List of usage examples for java.sql PreparedStatement setInt
void setInt(int parameterIndex, int x) throws SQLException;
int
value. From source file:com.concursive.connect.web.modules.profile.utils.ProjectUtils.java
/** * Accepts a project for the given user//from w w w .j av a 2 s .co m * * @param db Description of the Parameter * @param projectId Description of the Parameter * @param userId Description of the Parameter * @throws SQLException Description of the Exception */ public static void accept(Connection db, int projectId, int userId) throws SQLException { PreparedStatement pst = db.prepareStatement("UPDATE project_team " + "SET status = ? " + "WHERE project_id = ? " + "AND user_id = ? " + "AND status = ? "); DatabaseUtils.setInt(pst, 1, TeamMember.STATUS_ADDED); pst.setInt(2, projectId); pst.setInt(3, userId); pst.setInt(4, TeamMember.STATUS_PENDING); pst.executeUpdate(); pst.close(); CacheUtils.invalidateValue(Constants.SYSTEM_PROJECT_CACHE, projectId); }
From source file:com.aurel.track.dbase.MigrateTo37.java
private static void addLongTextFieldChange(PreparedStatement pstmtLongText, Integer fieldChangeID, Integer transactionID, String description) { try {//from w ww . j a va 2 s . c o m pstmtLongText.setInt(1, fieldChangeID); pstmtLongText.setInt(2, TFieldChangeBean.COMPOUND_HISTORY_FIELD); pstmtLongText.setInt(3, transactionID); pstmtLongText.setString(4, description); pstmtLongText.setInt(5, ValueType.LONGTEXT); pstmtLongText.setString(6, UUID.randomUUID().toString()); pstmtLongText.executeUpdate(); } catch (SQLException e) { LOGGER.error("Adding a field change for long text with transactionID " + transactionID + " fieldChangeID " + fieldChangeID + " failed with " + e.getMessage(), e); System.err.println(ExceptionUtils.getStackTrace(e)); } }
From source file:mitll.xdata.dataset.kiva.ingest.KivaIngest.java
public static int executePreparedStatement(PreparedStatement statement, List<String> types, List<String> values) throws Exception { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z"); try {//from w ww. j a va 2 s . c om for (int i = 0; i < types.size(); i++) { String type = TYPE_TO_DB.get(types.get(i).toUpperCase()); String value = values.get(i); if (value != null && value.trim().length() == 0) { value = null; } if (type.equalsIgnoreCase("INT")) { if (value == null) { statement.setNull(i + 1, java.sql.Types.INTEGER); } else { statement.setInt(i + 1, Integer.parseInt(value, 10)); } } else if (type.equalsIgnoreCase("DOUBLE")) { if (value == null) { statement.setNull(i + 1, java.sql.Types.DOUBLE); } else { statement.setDouble(i + 1, Double.parseDouble(value)); } } else if (type.equalsIgnoreCase("BOOLEAN")) { if (value == null) { statement.setNull(i + 1, java.sql.Types.BOOLEAN); } else { statement.setBoolean(i + 1, Boolean.parseBoolean(value)); } } else if (type.equalsIgnoreCase("VARCHAR")) { statement.setString(i + 1, value); } else if (type.equalsIgnoreCase("TIMESTAMP")) { if (value == null) { statement.setNull(i + 1, java.sql.Types.TIMESTAMP); } else { statement.setTimestamp(i + 1, new Timestamp(sdf.parse(value).getTime())); } } } } catch (Throwable e) { System.out.println("types = " + types); System.out.println("values = " + values); System.out.println("types.size() = " + types.size()); System.out.println("values.size() = " + values.size()); e.printStackTrace(); System.out.println(e.getMessage()); throw new Exception(e); } return statement.executeUpdate(); }
From source file:com.aurel.track.dbase.MigrateTo37.java
private static void addHistoryTransaction(PreparedStatement pstmtHistoryTransaction, int transactionID, Integer workItemID, Integer changedBy, Date lastEdit) { try {/*from w ww . jav a2 s .c o m*/ pstmtHistoryTransaction.setInt(1, transactionID); pstmtHistoryTransaction.setInt(2, workItemID); pstmtHistoryTransaction.setInt(3, changedBy); if (lastEdit == null) { pstmtHistoryTransaction.setDate(4, null); } else { pstmtHistoryTransaction.setTimestamp(4, new java.sql.Timestamp(lastEdit.getTime())); } pstmtHistoryTransaction.setString(5, UUID.randomUUID().toString()); pstmtHistoryTransaction.executeUpdate(); } catch (Exception e) { LOGGER.error("Adding a transaction with transactionID " + transactionID + " workItemID " + workItemID + " changedBy " + changedBy + " at " + lastEdit + " failed with " + e.getMessage(), e); System.err.println(ExceptionUtils.getStackTrace(e)); } }
From source file:fll.web.admin.UploadSubjectiveData.java
/** * Remove rows from the specified subjective category that are empty. These * are rows that have null for all scores and is not a no show. * /*ww w.ja v a2 s . c om*/ * @param currentTournament * @param connection * @param categoryName * @param categoryElement * @throws SQLException */ @SuppressFBWarnings(value = { "SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING" }, justification = "columns are dynamic") private static void removeNullRows(final int currentTournament, final Connection connection, final String categoryName, final ScoreCategory categoryElement) throws SQLException { final List<AbstractGoal> goalDescriptions = categoryElement.getGoals(); PreparedStatement prep = null; try { final StringBuffer sql = new StringBuffer(); sql.append("DELETE FROM " + categoryName + " WHERE NoShow <> ? "); for (final AbstractGoal goalDescription : goalDescriptions) { sql.append(" AND " + goalDescription.getName() + " IS NULL "); } sql.append(" AND Tournament = ?"); prep = connection.prepareStatement(sql.toString()); prep.setBoolean(1, true); prep.setInt(2, currentTournament); prep.executeUpdate(); } finally { SQLFunctions.close(prep); } }
From source file:com.aurel.track.dbase.MigrateTo37.java
private static void addBaseLineChange(PreparedStatement pstmtBaseLineChange, Integer fieldChangeID, Integer transactionID, int fieldKey, Date newDate, Date oldDate) { try {/*from w w w . j a v a 2 s . c om*/ pstmtBaseLineChange.setInt(1, fieldChangeID); pstmtBaseLineChange.setInt(2, fieldKey); pstmtBaseLineChange.setInt(3, transactionID); if (newDate == null) { pstmtBaseLineChange.setDate(4, null); } else { pstmtBaseLineChange.setDate(4, new java.sql.Date(newDate.getTime())); } if (oldDate == null) { pstmtBaseLineChange.setDate(5, null); } else { pstmtBaseLineChange.setDate(5, new java.sql.Date(oldDate.getTime())); } pstmtBaseLineChange.setInt(6, ValueType.DATE); pstmtBaseLineChange.setString(7, UUID.randomUUID().toString()); pstmtBaseLineChange.executeUpdate(); } catch (SQLException e) { LOGGER.error("Adding a field change for base line with transactionID " + transactionID + " fieldChangeID " + fieldChangeID + " fieldKey " + fieldKey + " newDate " + newDate + " oldDate " + oldDate + " failed with " + e.getMessage(), e); System.err.println(ExceptionUtils.getStackTrace(e)); } }
From source file:com.concursive.connect.web.modules.documents.dao.FileFolder.java
/** * Description of the Method//from ww w . j a va 2 s .co m * * @param db Description of the Parameter * @param hierarchy Description of the Parameter * @param currentId Description of the Parameter * @throws SQLException Description of the Exception */ public static void buildHierarchy(Connection db, Map hierarchy, int currentId) throws SQLException { PreparedStatement pst = db.prepareStatement( "SELECT parent_id, subject, display " + "FROM project_folders " + "WHERE folder_id = ? "); pst.setInt(1, currentId); ResultSet rs = pst.executeQuery(); int parentId = 0; String subject = null; int display = -1; if (rs.next()) { parentId = DatabaseUtils.getInt(rs, "parent_id"); subject = rs.getString("subject"); display = DatabaseUtils.getInt(rs, "display"); } rs.close(); pst.close(); hierarchy.put(new Integer(currentId), new String[] { subject, String.valueOf(display) }); if (parentId > -1) { FileFolder.buildHierarchy(db, hierarchy, parentId); } }
From source file:com.wso2telco.proxy.util.DBUtils.java
private static List<LoginHintFormatDetails> getLoginHintFormatTypeDetails(int paramId, Connection conn) throws AuthenticatorException, SQLException { PreparedStatement ps = null; ResultSet results = null;/*w ww . ja v a 2s .c o m*/ String sql = "SELECT * FROM `login_hint_format` WHERE `format_id` IN (SELECT `format_id` FROM " + "`scope_supp_login_hint_format` WHERE `param_id` = ?);"; if (log.isDebugEnabled()) { log.debug("Executing the query : " + sql); } List<LoginHintFormatDetails> loginHintFormatDetails = new ArrayList<LoginHintFormatDetails>(); try { ps = conn.prepareStatement(sql); ps.setInt(1, paramId); results = ps.executeQuery(); while (results.next()) { LoginHintFormatDetails loginHintFormat = new LoginHintFormatDetails(); loginHintFormat.setFormatType( LoginHintFormatDetails.loginHintFormatTypes.valueOf(results.getString("type"))); loginHintFormat.setEncrypted(results.getBoolean("is_encrypted")); loginHintFormat.setDecryptAlgorithm(results.getString("decrypt_algorithm")); loginHintFormatDetails.add(loginHintFormat); } } catch (SQLException e) { //using the same connection to avoid connection pool exhaust exception within the loop. SQL exception to // be handled in the parent function. log.error("Error occurred while getting login format details from the database", e); throw e; } finally { closeAllConnections(ps, null, results); } return loginHintFormatDetails; }
From source file:com.stratelia.webactiv.util.DBUtil.java
protected static int getMaxId(Connection privateConnection, String tableName, String idName) throws SQLException { // tentative d'update SilverTrace.debug("util", "DBUtil.getNextId", "dBName = " + tableName); try {// w w w. ja v a2 s .c o m int max = updateMaxFromTable(privateConnection, tableName); privateConnection.commit(); return max; } catch (Exception e) { // l'update n'a rien fait, il faut recuperer une valeur par defaut. // on recupere le max (depuis la table existante du composant) SilverTrace.debug("util", "DBUtil.getNextId", "impossible d'updater, if faut recuperer la valeur initiale", e); } int max = getMaxFromTable(privateConnection, tableName, idName); PreparedStatement createStmt = null; try { // on enregistre le max String createStatement = "INSERT INTO UniqueId (maxId, tableName) VALUES (?, ?)"; createStmt = privateConnection.prepareStatement(createStatement); createStmt.setInt(1, max); createStmt.setString(2, tableName.toLowerCase()); createStmt.executeUpdate(); privateConnection.commit(); return max; } catch (Exception e) { // impossible de creer, on est en concurence, on reessaye l'update. SilverTrace.debug("util", "DBUtil.getNextId", "impossible de creer, if faut reessayer l'update", e); rollback(privateConnection); } finally { close(createStmt); } max = updateMaxFromTable(privateConnection, tableName); privateConnection.commit(); return max; }
From source file:at.becast.youploader.database.SQLite.java
public static void insertPlaylist(Item item, int account) throws SQLException, IOException { PreparedStatement prest = null; String sql = "INSERT INTO `playlists` (`name`, `playlistid`,`image`,`account`,`shown`) " + "VALUES (?,?,?,?,1)"; prest = c.prepareStatement(sql);/*from w w w .j a v a2 s .c o m*/ prest.setString(1, item.snippet.title); prest.setString(2, item.id); URL url = new URL(item.snippet.thumbnails.default__.url); InputStream is = null; is = url.openStream(); byte[] imageBytes = IOUtils.toByteArray(is); prest.setBytes(3, imageBytes); prest.setInt(4, account); prest.execute(); prest.close(); }