List of usage examples for java.sql PreparedStatement setBoolean
void setBoolean(int parameterIndex, boolean x) throws SQLException;
boolean
value. From source file:org.josso.gateway.assertion.service.store.db.DbAssertionStore.java
protected void insert(Connection conn, AuthenticationAssertion assertion) throws SQLException { final PreparedStatement ps = conn.prepareStatement(_insertDml); ps.setString(1, assertion.getId());/*from w ww . j a v a 2 s . co m*/ ps.setString(2, "default"); ps.setString(3, assertion.getSSOSessionId()); ps.setLong(4, assertion.getCreationTime()); ps.setBoolean(5, assertion.isValid()); ps.execute(); if (__log.isDebugEnabled()) __log.debug( "Creation, LastAccess: " + assertion.getCreationTime() + ", " + assertion.getCreationTime()); if (__log.isDebugEnabled()) __log.debug("Assertion inserted: " + assertion.getId()); }
From source file:com.alfaariss.oa.authentication.remote.aselect.idp.storage.jdbc.IDPJDBCStorage.java
/** * @see com.alfaariss.oa.engine.core.idp.storage.IIDPStorage#getIDP(java.lang.Object, java.lang.String) *//* w w w.ja va2s.co m*/ public IIDP getIDP(Object id, String type) throws OAException { Connection connection = null; PreparedStatement pSelect = null; ResultSet resultSet = null; ASelectIDP oASelectIDP = null; try { connection = _dataSource.getConnection(); StringBuffer sbSelect = new StringBuffer(_querySelectAll); sbSelect.append(" AND "); sbSelect.append(type); sbSelect.append("=?"); pSelect = connection.prepareStatement(sbSelect.toString()); pSelect.setBoolean(1, true); pSelect.setObject(2, id); resultSet = pSelect.executeQuery(); if (resultSet.next()) { oASelectIDP = new ASelectIDP(resultSet.getString(COLUMN_ID), resultSet.getString(COLUMN_FRIENDLYNAME), resultSet.getString(COLUMN_SERVER_ID), resultSet.getString(COLUMN_URL), resultSet.getInt(COLUMN_LEVEL), resultSet.getBoolean(COLUMN_SIGNING), resultSet.getString(COLUMN_COUNTRY), resultSet.getString(COLUMN_LANGUAGE), resultSet.getBoolean(COLUMN_ASYNCHRONOUS_LOGOUT), resultSet.getBoolean(COLUMN_SYNCHRONOUS_LOGOUT), resultSet.getBoolean(COLUMN_SEND_ARP_TARGET)); } } catch (Exception e) { _logger.fatal("Internal error during retrieval of IDP with id: " + id, e); throw new OAException(SystemErrors.ERROR_INTERNAL); } finally { try { if (pSelect != null) pSelect.close(); } catch (Exception e) { _logger.error("Could not close select statement", e); } try { if (connection != null) connection.close(); } catch (Exception e) { _logger.error("Could not close connection", e); } } return oASelectIDP; }
From source file:com.darkenedsky.reddit.traders.RedditTraders.java
/** * Internal method to do the actual setting of flair * /*from w ww. j a v a 2 s .co m*/ * * @param user * Redditor's username * @param subreddit * The subreddit being traded on * @param doTextFlair * 'true' if the TEXTFLAIR option is turned on for this subreddit * * @throws MalformedURLException * @throws IOException * @throws ParseException * @throws SQLException */ public void setUserFlair(String user, String subreddit, boolean doTextFlair) throws SQLException, MalformedURLException, IOException, ParseException { int trades = 0; String flair = null; PreparedStatement ps1 = config.getJDBC().prepareStatement( "select * from get_trade_count_with_countall((select redditorid from redditors where username ilike ?), (select redditid from subreddits where subreddit ilike ?));"); ps1.setString(1, user); ps1.setString(2, subreddit); ResultSet set1 = ps1.executeQuery(); if (set1.first()) { trades = set1.getInt("get_trade_count_with_countall"); } set1.close(); PreparedStatement ps2 = config.getJDBC().prepareStatement("select * from get_flair_class(?,?,?);"); ps2.setString(1, user); ps2.setString(2, subreddit); ps2.setBoolean(3, isModerator(user, subreddit)); ResultSet set2 = ps2.executeQuery(); if (set2.first()) { flair = set2.getString("get_flair_class"); } set2.close(); if (flair == null) { LOG.debug("No flair matching criteria for user."); return; } String tradeCount = ""; if (doTextFlair) { tradeCount = "&text=" + Integer.toString(trades) + " trade" + ((trades != 1) ? "s" : ""); } LOG.debug("Posting flair..."); String post = "uh=" + config.getBotUser().getModhash() + "&name=" + user + "&r=" + subreddit + "&css_class=" + flair + tradeCount; LOG.debug(post); Utils.post(post, new URL("http://www.reddit.com/api/flair"), config.getBotUser().getCookie()); LOG.debug("Flair posted."); }
From source file:org.cloudfoundry.identity.uaa.scim.dao.standard.JdbcScimUserProvisioning.java
@Override public ScimUserInterface update(final String id, final ScimUserInterface user) throws InvalidScimResourceException { validate(user);//from ww w .ja v a 2 s . c om logger.debug("Updating user " + user.getUserName()); int updated = jdbcTemplate.update(UPDATE_USER_SQL, new PreparedStatementSetter() { @Override public void setValues(PreparedStatement ps) throws SQLException { ps.setInt(1, user.getVersion() + 1); ps.setTimestamp(2, new Timestamp(new Date().getTime())); ps.setString(3, user.getUserName()); ps.setString(4, user.getPrimaryEmail()); ps.setString(5, user.getGivenName()); ps.setString(6, user.getFamilyName()); ps.setBoolean(7, user.isActive()); ps.setString(8, extractPhoneNumber(user)); ps.setBoolean(9, user.isVerified()); ps.setString(10, id); ps.setInt(11, user.getVersion()); } }); ScimUserInterface result = retrieve(id); if (updated == 0) { throw new OptimisticLockingFailureException( String.format("Attempt to update a user (%s) with wrong version: expected=%d but found=%d", id, result.getVersion(), user.getVersion())); } if (updated > 1) { throw new IncorrectResultSizeDataAccessException(1); } return result; }
From source file:org.cloudfoundry.identity.uaa.scim.JdbcScimUserProvisioning.java
@Override public ScimUser updateUser(final String id, final ScimUser user) throws InvalidUserException { validate(user);//from w w w.j a va 2 s . c om logger.info("Updating user " + user.getUserName()); int updated = jdbcTemplate.update(UPDATE_USER_SQL, new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { ps.setInt(1, user.getVersion() + 1); ps.setTimestamp(2, new Timestamp(new Date().getTime())); ps.setString(3, user.getPrimaryEmail()); ps.setString(4, user.getName().getGivenName()); ps.setString(5, user.getName().getFamilyName()); ps.setBoolean(6, user.isActive()); ps.setLong(7, UaaAuthority.fromUserType(user.getUserType()).value()); ps.setString(8, extractPhoneNumber(user)); ps.setString(9, id); ps.setInt(10, user.getVersion()); } }); ScimUser result = retrieveUser(id); if (updated == 0) { throw new OptimisticLockingFailureException( String.format("Attempt to update a user (%s) with wrong version: expected=%d but found=%d", id, result.getVersion(), user.getVersion())); } if (updated > 1) { throw new IncorrectResultSizeDataAccessException(1); } return result; }
From source file:org.apache.hadoop.hive.ql.metadata.BIStore.java
public int updateDDLQueryInfo(Connection cc, String qid, boolean ddlQueryRes, String taskId, String userName) { int rt = -1;//from w ww . j av a 2 s.co m PreparedStatement pstmt; if (cc == null || qid == null) { return -1; } try { pstmt = cc.prepareStatement("update TDW_DDL_QUERY_INFO set FINISHTIME = 'now()', " + "USERNAME = ?, QUERYRESULT = ?, TASKID = ? WHERE QUERYID = ?"); pstmt.setString(1, userName); pstmt.setBoolean(2, ddlQueryRes); pstmt.setString(3, taskId); pstmt.setString(4, qid); rt = pstmt.executeUpdate(); } catch (SQLException e) { LOG.error(" updateInfo failed: " + qid); e.printStackTrace(); } return rt; }
From source file:net.dv8tion.discord.commands.TodoCommand.java
private void handleAdd(MessageReceivedEvent e, String[] args) throws SQLException { checkArgs(args, 2,// w ww . j a v a 2s . co m "No todo ListName was specified. Usage: `" + getAliases().get(0) + " add [ListName] [content...]`"); checkArgs(args, 3, "No content was specified. Cannot create an empty todo entry!" + "Usage: `" + getAliases().get(0) + " add [ListName] [content...]`"); String label = args[2].toLowerCase(); String content = StringUtils.join(args, " ", 3, args.length); TodoList todoList = todoLists.get(label); if (todoList == null) { sendMessage(e, "Sorry, `" + label + "` isn't a known todo list. " + "Try using `" + getAliases().get(0) + " create " + label + "` to create a new list by this name."); return; } if (todoList.locked && !todoList.isAuthUser(e.getAuthor())) { sendMessage(e, "Sorry, `" + label + "` is a locked todo list and you do not have permission to modify it."); return; } PreparedStatement addTodoEntry = Database.getInstance().getStatement(ADD_TODO_ENTRY); addTodoEntry.setInt(1, todoList.id); addTodoEntry.setString(2, content); addTodoEntry.setBoolean(3, false); if (addTodoEntry.executeUpdate() == 0) throw new SQLException(ADD_TODO_ENTRY + " reported no modified rows!"); todoList.entries.add(new TodoEntry(Database.getAutoIncrement(addTodoEntry, 1), content, false)); addTodoEntry.clearParameters(); sendMessage(e, "Added to `" + label + "` todo list."); }
From source file:org.eclipse.ecr.core.storage.sql.jdbc.dialect.DialectOracle.java
@Override public void setToPreparedStatement(PreparedStatement ps, int index, Serializable value, Column column) throws SQLException { switch (column.getJdbcType()) { case Types.VARCHAR: case Types.CLOB: setToPreparedStatementString(ps, index, value, column); return;//from w ww . j a v a 2s . c om case Types.BIT: ps.setBoolean(index, ((Boolean) value).booleanValue()); return; case Types.TINYINT: case Types.SMALLINT: ps.setInt(index, ((Long) value).intValue()); return; case Types.INTEGER: case Types.BIGINT: ps.setLong(index, ((Long) value).longValue()); return; case Types.DOUBLE: ps.setDouble(index, ((Double) value).doubleValue()); return; case Types.TIMESTAMP: setToPreparedStatementTimestamp(ps, index, value, column); return; default: throw new SQLException("Unhandled JDBC type: " + column.getJdbcType()); } }
From source file:com.ewcms.component.interaction.dao.InteractionDAO.java
@Override public Integer addInteraction(final Interaction vo) { final String sql = "Insert Into plugin_interaction " + "(username,title,content,replay,type,state,checked,organ_id,ip,name,organ_name,tel) " + "Values (?,?,?,?,?,?,?,?,?,?,?,?)"; jdbcTemplate.update(new PreparedStatementCreator() { @Override//from w w w . ja va2 s .c om public PreparedStatement createPreparedStatement(Connection con) throws SQLException { PreparedStatement ps = con.prepareStatement(sql); ps.setString(1, vo.getUsername()); ps.setString(2, vo.getTitle()); ps.setString(3, vo.getContent()); ps.setString(4, vo.getReplay()); ps.setInt(5, vo.getType()); ps.setInt(6, vo.getState().ordinal()); ps.setBoolean(7, vo.getChecked()); ps.setInt(8, vo.getOrgan().getId()); ps.setString(9, vo.getIp()); ps.setString(10, vo.getName()); ps.setString(11, vo.getOrgan().getName()); ps.setString(12, vo.getTel()); return ps; } }); return jdbcTemplate.queryForInt("select currval('seq_plugin_interaction_id')"); }
From source file:com.nabla.wapp.server.auth.UserManager.java
public boolean initializeDatabase(final IRoleListProvider roleListProvider, final String rootPassword) throws SQLException { Assert.argumentNotNull(roleListProvider); final LockTableGuard lock = new LockTableGuard(conn, LOCK_USER_TABLES); try {// ww w . ja va2 s. c o m if (!Database.isTableEmpty(conn, IRoleTable.TABLE)) return true; if (log.isDebugEnabled()) log.debug("initializing role tables"); final Map<String, String[]> roles = roleListProvider.get(); Assert.state(!roles.containsKey(IRootUser.NAME)); final ConnectionTransactionGuard guard = new ConnectionTransactionGuard(conn); try { final PreparedStatement stmtRole = conn.prepareStatement( "INSERT INTO role (name,uname,privilege,internal) VALUES(?,?,?,?);", Statement.RETURN_GENERATED_KEYS); final Map<String, Integer> roleIds = new HashMap<String, Integer>(); try { stmtRole.clearBatch(); stmtRole.setBoolean(4, true); // add privileges and default roles for (final Map.Entry<String, String[]> role : roles.entrySet()) { stmtRole.setString(1, role.getKey()); stmtRole.setString(2, role.getKey().toUpperCase()); stmtRole.setBoolean(3, role.getValue() == null); stmtRole.addBatch(); } if (!Database.isBatchCompleted(stmtRole.executeBatch())) return false; final ResultSet rsKey = stmtRole.getGeneratedKeys(); try { for (final Map.Entry<String, String[]> role : roles.entrySet()) { rsKey.next(); roleIds.put(role.getKey(), rsKey.getInt(1)); } } finally { rsKey.close(); } } finally { stmtRole.close(); } final PreparedStatement stmtDefinition = conn .prepareStatement("INSERT INTO role_definition (role_id,child_role_id) VALUES(?,?);"); try { stmtDefinition.clearBatch(); for (final Map.Entry<String, String[]> role : roles.entrySet()) { final String[] definition = role.getValue(); if (definition == null) continue; stmtDefinition.setInt(1, roleIds.get(role.getKey())); for (final String child : definition) { final Integer childId = roleIds.get(child); if (childId == null) { if (log.isErrorEnabled()) log.error("child role '" + child + "' not defined!"); return false; } stmtDefinition.setInt(2, childId); stmtDefinition.addBatch(); } } if (!Database.isBatchCompleted(stmtDefinition.executeBatch())) return false; } finally { stmtDefinition.close(); } // add 'root' user Database.executeUpdate(conn, "INSERT INTO user (name,uname,active,password) VALUES(?,?,TRUE,?);", IRootUser.NAME, IRootUser.NAME.toUpperCase(), getPasswordEncryptor().encryptPassword(rootPassword)); return guard.setSuccess(true); } finally { guard.close(); } } finally { lock.close(); } }