List of usage examples for java.sql PreparedStatement setBoolean
void setBoolean(int parameterIndex, boolean x) throws SQLException;
boolean
value. From source file:dsd.dao.DAOProvider.java
/** * calls the correct method for setting the command parameter depending on * parameter type//from w w w . j a v a 2s. c o m * * @param command * @param object * @param parameterIndex * @throws SQLException */ private static void SetParameter(PreparedStatement command, Object object, int parameterIndex) throws SQLException { if (object instanceof Timestamp) { command.setTimestamp(parameterIndex, (Timestamp) object); } else if (object instanceof String) { command.setString(parameterIndex, (String) object); } else if (object instanceof Long) { command.setLong(parameterIndex, (Long) object); } else if (object instanceof Integer) { command.setInt(parameterIndex, (Integer) object); } else if (object instanceof Boolean) { command.setBoolean(parameterIndex, (Boolean) object); } else if (object instanceof Float) { command.setFloat(parameterIndex, (Float) object); } else { throw new IllegalArgumentException( "type needs to be inserted in Set parameter method of DAOProvider class"); } }
From source file:Main.java
public static PreparedStatement createFieldsInsert(Connection conn, int layerId, String name, String description, String fieldId, String fieldType, String sid, String sname, String sdesc, boolean indb, boolean enabled, boolean namesearch, boolean defaultlayer, boolean intersect, boolean layerbranch, boolean analysis, boolean addToMap) throws SQLException { // TOOD slightly different statement if sdesc is null... PreparedStatement stFieldsInsert = conn.prepareStatement( "INSERT INTO fields (name, id, \"desc\", type, spid, sid, sname, sdesc, indb, enabled, last_update, namesearch, defaultlayer, \"intersect\", layerbranch, analysis, addtomap)" + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"); stFieldsInsert.setString(1, name);//from ww w. java2s.c om stFieldsInsert.setString(2, fieldId); stFieldsInsert.setString(3, description); stFieldsInsert.setString(4, fieldType); stFieldsInsert.setString(5, Integer.toString(layerId)); stFieldsInsert.setString(6, sid); stFieldsInsert.setString(7, sname); if (sdesc == null || sdesc.isEmpty()) { stFieldsInsert.setNull(8, Types.VARCHAR); } else { stFieldsInsert.setString(8, sdesc); } stFieldsInsert.setBoolean(9, indb); stFieldsInsert.setBoolean(10, enabled); stFieldsInsert.setTimestamp(11, new Timestamp(System.currentTimeMillis())); stFieldsInsert.setBoolean(12, namesearch); stFieldsInsert.setBoolean(13, defaultlayer); stFieldsInsert.setBoolean(14, intersect); stFieldsInsert.setBoolean(15, layerbranch); stFieldsInsert.setBoolean(16, analysis); stFieldsInsert.setBoolean(17, addToMap); return stFieldsInsert; }
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. * /*from w w w. j av a 2 s .com*/ * @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.flexive.core.security.FxDBAuthentication.java
/** * Mark a user as no longer active in the database. * * @param ticket the ticket of the user// ww w . ja v a 2s . co m * @throws javax.security.auth.login.LoginException * if the function failed */ public static void logout(UserTicket ticket) throws LoginException { PreparedStatement ps = null; String curSql; Connection con = null; FxContext inf = FxContext.get(); try { // Obtain a database connection con = Database.getDbConnection(); // EJBLookup user in the database, combined with a update statement to make sure // nothing changes between the lookup/set ISLOGGEDIN flag. curSql = "UPDATE " + TBL_ACCOUNT_DETAILS + " SET ISLOGGEDIN=? WHERE ID=? AND APPLICATION=?"; ps = con.prepareStatement(curSql); ps.setBoolean(1, false); ps.setLong(2, ticket.getUserId()); ps.setString(3, inf.getApplicationId()); // Not more than one row should be affected, or the logout failed final int rowCount = ps.executeUpdate(); if (rowCount > 1) { // Logout failed. LoginException le = new LoginException("Logout for user [" + ticket.getUserId() + "] failed"); LOG.error(le); throw le; } } catch (SQLException exc) { LoginException le = new LoginException("Database error: " + exc.getMessage()); LOG.error(le); throw le; } finally { Database.closeObjects(FxDBAuthentication.class, con, ps); } }
From source file:nl.strohalm.cyclos.utils.JDBCWrapper.java
/** * Set the given positional parameters on a prepared statement, guessing the argument types *//*from w w w .jav a2 s . com*/ private static void setParameters(final PreparedStatement ps, final Object... parameters) throws SQLException { if (ps == null || ArrayUtils.isEmpty(parameters)) { return; } for (int i = 0; i < parameters.length; i++) { final Object object = parameters[i]; final int index = i + 1; if (object instanceof Number) { ps.setBigDecimal(index, CoercionHelper.coerce(BigDecimal.class, object)); } else if ((object instanceof Calendar) || (object instanceof Date)) { final Calendar cal = CoercionHelper.coerce(Calendar.class, object); ps.setTimestamp(index, new Timestamp(cal.getTimeInMillis())); } else if (object instanceof Boolean) { ps.setBoolean(index, (Boolean) object); } else { ps.setString(index, CoercionHelper.coerce(String.class, object)); } } }
From source file:com.flexive.core.security.FxDBAuthentication.java
/** * Increase the number of failed login attempts for the given user * * @param con an open and valid connection * @param userId user id/*from w w w. jav a 2 s.c o m*/ * @throws SQLException on errors */ private static void increaseFailedLoginAttempts(Connection con, long userId) throws SQLException { PreparedStatement ps = null; try { ps = con.prepareStatement( "UPDATE " + TBL_ACCOUNT_DETAILS + " SET FAILED_ATTEMPTS=FAILED_ATTEMPTS+1 WHERE ID=?"); ps.setLong(1, userId); if (ps.executeUpdate() == 0) { ps.close(); ps = con.prepareStatement("INSERT INTO " + TBL_ACCOUNT_DETAILS + " (ID,APPLICATION,ISLOGGEDIN,LAST_LOGIN,LAST_LOGIN_FROM,FAILED_ATTEMPTS,AUTHSRC) " + "VALUES (?,?,?,?,?,?,?)"); ps.setLong(1, userId); ps.setString(2, FxContext.get().getApplicationId()); ps.setBoolean(3, false); ps.setLong(4, System.currentTimeMillis()); ps.setString(5, FxContext.get().getRemoteHost()); ps.setLong(6, 1); //one failed attempt ps.setString(7, AuthenticationSource.Database.name()); ps.executeUpdate(); } } finally { if (ps != null) ps.close(); } }
From source file:com.useekm.indexing.postgis.IndexedStatement.java
private static void addBindings(PreparedStatement stat, Resource subject, URI predicate, Value object) throws SQLException { int idx = 1;/* w w w . jav a 2 s .com*/ if (subject != null) stat.setString(idx++, subject.stringValue()); if (predicate != null) stat.setString(idx++, predicate.stringValue()); if (object != null) { stat.setString(idx++, object.stringValue()); stat.setString(idx++, object.stringValue()); if (object instanceof URI) stat.setBoolean(idx++, true); else { stat.setBoolean(idx++, false); stat.setString(idx++, getDataTypeAsString(object)); stat.setString(idx++, normalizeLang(((Literal) object).getLanguage())); } } }
From source file:org.apache.lucene.store.jdbc.handler.MarkDeleteFileEntryHandler.java
public void deleteFile(final String name) throws IOException { jdbcTemplate.update(table.sqlMarkDeleteByName(), new PreparedStatementSetter() { @Override/*from w w w. jav a 2 s .c o m*/ public void setValues(PreparedStatement ps) throws SQLException { ps.setFetchSize(1); ps.setBoolean(1, true); ps.setString(2, name); } }); }
From source file:com.concursive.connect.web.modules.register.beans.RegisterBean.java
/** * Description of the Method/* ww w.java 2 s.c o m*/ * * @param db Description of the Parameter * @param partialUserRecord Description of the Parameter * @return Description of the Return Value * @throws SQLException Description of the Exception */ private static void updateRegisteredStatus(Connection db, User partialUserRecord) throws SQLException { // NOTE: Assume the user object isn't complete, so can't load it, etc. { // Approve the user PreparedStatement pst = db .prepareStatement("UPDATE users " + "SET first_name = ?, last_name = ?, password = ?, " + "company = ?, registered = ?, enabled = ?, terms = ? " + "WHERE user_id = ? "); int i = 0; pst.setString(++i, partialUserRecord.getFirstName()); pst.setString(++i, partialUserRecord.getLastName()); pst.setString(++i, partialUserRecord.getPassword()); pst.setString(++i, partialUserRecord.getCompany()); pst.setBoolean(++i, true); pst.setBoolean(++i, true); pst.setBoolean(++i, partialUserRecord.getTerms()); pst.setInt(++i, partialUserRecord.getId()); pst.executeUpdate(); pst.close(); CacheUtils.invalidateValue(Constants.SYSTEM_USER_CACHE, partialUserRecord.getId()); } { // Approve the user's profile and update their location User user = UserUtils.loadUser(partialUserRecord.getId()); if (user == null) { LOG.warn("updateRegisteredStatus - USER RECORD IS NULL"); } else { Project profile = ProjectUtils.loadProject(user.getProfileProjectId()); if (profile == null) { LOG.warn("updateRegisteredStatus - PROFILE RECORD IS NULL"); } else { profile.setApproved(true); profile.setCity(partialUserRecord.getCity()); profile.setState(partialUserRecord.getState()); profile.setCountry(partialUserRecord.getCountry()); profile.setPostalCode(partialUserRecord.getPostalCode()); profile.update(db); } } } }
From source file:org.apache.lucene.store.jdbc.handler.MarkDeleteFileEntryHandler.java
public List deleteFiles(final List names) throws IOException { jdbcTemplate.batchUpdate(table.sqlMarkDeleteByName(), new BatchPreparedStatementSetter() { @Override//from w w w . j a va 2s . c om public void setValues(PreparedStatement ps, int i) throws SQLException { ps.setFetchSize(1); ps.setBoolean(1, true); ps.setString(2, (String) names.get(i)); ps.addBatch(); } @Override public int getBatchSize() { return names.size(); } }); return null; }