List of usage examples for java.sql PreparedStatement setBoolean
void setBoolean(int parameterIndex, boolean x) throws SQLException;
boolean
value. From source file:mysql5.MySQL5PlayerDAO.java
@Override public int getOnlinePlayerCount() { Connection con = null;/* w w w . java 2s . com*/ int count = 0; try { con = DatabaseFactory.getConnection(); PreparedStatement stmt = con .prepareStatement("SELECT COUNT(*) AS `count` FROM `players` WHERE `online` = ?"); stmt.setBoolean(1, true); ResultSet rs = stmt.executeQuery(); rs.next(); count = rs.getInt("count"); rs.close(); stmt.close(); } catch (Exception e) { return 0; } finally { DatabaseFactory.close(con); } return count; }
From source file:org.cloudfoundry.identity.uaa.provider.JdbcIdentityProviderProvisioning.java
@Override public IdentityProvider create(final IdentityProvider identityProvider) { validate(identityProvider);//w w w. j a v a 2 s .c o m final String id = UUID.randomUUID().toString(); try { jdbcTemplate.update(CREATE_IDENTITY_PROVIDER_SQL, new PreparedStatementSetter() { @Override public void setValues(PreparedStatement ps) throws SQLException { int pos = 1; ps.setString(pos++, id); ps.setInt(pos++, identityProvider.getVersion()); ps.setTimestamp(pos++, new Timestamp(System.currentTimeMillis())); ps.setTimestamp(pos++, new Timestamp(System.currentTimeMillis())); ps.setString(pos++, identityProvider.getName()); ps.setString(pos++, identityProvider.getOriginKey()); ps.setString(pos++, identityProvider.getType()); ps.setString(pos++, JsonUtils.writeValueAsString(identityProvider.getConfig())); ps.setString(pos++, identityProvider.getIdentityZoneId()); ps.setBoolean(pos++, identityProvider.isActive()); } }); } catch (DuplicateKeyException e) { throw new IdpAlreadyExistsException(e.getMostSpecificCause().getMessage()); } return retrieve(id); }
From source file:com.alfaariss.oa.authentication.remote.saml2.idp.storage.jdbc.IDPJDBCStorage.java
/** * @see com.alfaariss.oa.engine.core.idp.storage.IIDPStorage#getAll() *//* w ww. ja v a 2 s . c o m*/ public List<IIDP> getAll() throws OAException { Connection connection = null; PreparedStatement pSelect = null; ResultSet resultSet = null; List<IIDP> listIDPs = new Vector<IIDP>(); IMetadataProviderManager oMPM = MdMgrManager.getInstance().getMetadataProviderManager(_sId); try { boolean dateLastModifiedExists = true; connection = _dataSource.getConnection(); pSelect = connection.prepareStatement(_sQuerySelectAll); pSelect.setBoolean(1, true); resultSet = pSelect.executeQuery(); while (resultSet.next()) { boolean bACSIndex = resultSet.getBoolean(COLUMN_ACS_INDEX); Boolean boolAllowCreate = null; String sAllowCreate = resultSet.getString(COLUMN_ALLOW_CREATE); if (sAllowCreate != null) { boolean bAllowCreate = resultSet.getBoolean(COLUMN_ALLOW_CREATE); boolAllowCreate = new Boolean(bAllowCreate); } boolean bScoping = resultSet.getBoolean(COLUMN_SCOPING); boolean bNameIDPolicy = resultSet.getBoolean(COLUMN_NAMEIDPOLICY); boolean bAvoidSubjectConfirmation = resultSet.getBoolean(COLUMN_AVOID_SUBJCONF); boolean bDisableSSOForIDP = resultSet.getBoolean(COLUMN_DISABLE_SSO); // Implement date_last_modified column as optional Date dLastModified = null; if (dateLastModifiedExists) { try { dLastModified = resultSet.getTimestamp(COLUMN_DATELASTMODIFIED); } catch (Exception e) { _oLogger.info("No " + COLUMN_DATELASTMODIFIED + " column found; ignoring."); dateLastModifiedExists = false; } } SAML2IDP idp = new SAML2IDP(resultSet.getString(COLUMN_ID), resultSet.getBytes(COLUMN_SOURCEID), resultSet.getString(COLUMN_FRIENDLYNAME), resultSet.getString(COLUMN_METADATA_FILE), resultSet.getString(COLUMN_METADATA_URL), resultSet.getInt(COLUMN_METADATA_TIMEOUT), bACSIndex, boolAllowCreate, bScoping, bNameIDPolicy, resultSet.getString(COLUMN_NAMEIDFORMAT), bAvoidSubjectConfirmation, bDisableSSOForIDP, dLastModified, oMPM.getId()); listIDPs.add(idp); } } catch (Exception e) { _oLogger.fatal("Internal error during retrieval of all IDPs", e); throw new OAException(SystemErrors.ERROR_INTERNAL); } finally { try { if (pSelect != null) pSelect.close(); } catch (Exception e) { _oLogger.error("Could not close select statement", e); } try { if (connection != null) connection.close(); } catch (Exception e) { _oLogger.error("Could not close connection", e); } } return listIDPs; }
From source file:mysql5.MySQL5PlayerDAO.java
/** * {@inheritDoc} - Saelya//from ww w . j a v a2 s . co m */ @Override public void onlinePlayer(final Player player, final boolean online) { DB.insertUpdate("UPDATE players SET online=? WHERE id=?", new IUStH() { @Override public void handleInsertUpdate(PreparedStatement stmt) throws SQLException { log.debug("[DAO: MySQL5PlayerDAO] online status " + player.getObjectId() + " " + player.getName()); stmt.setBoolean(1, online); stmt.setInt(2, player.getObjectId()); stmt.execute(); } }); }
From source file:com.concursive.connect.web.modules.documents.dao.FileItem.java
/** * Description of the Method/*from w w w. j a va 2 s. c om*/ * * @param db Description of the Parameter * @param linkModuleId Description of the Parameter * @param linkItemId Description of the Parameter * @param id Description of the Parameter * @throws SQLException Description of the Exception */ public static synchronized void updateDefaultRecord(Connection db, int linkModuleId, int linkItemId, int id) throws SQLException { // Turn off other defaults PreparedStatement pst = db.prepareStatement("UPDATE project_files " + "SET default_file = ? " + "WHERE link_module_id = ? " + "AND link_item_id = ? " + "AND default_file = ? "); int i = 0; pst.setBoolean(++i, false); pst.setInt(++i, linkModuleId); pst.setInt(++i, linkItemId); pst.setBoolean(++i, true); pst.execute(); pst.close(); // Turn on this default pst = db.prepareStatement( "UPDATE project_files " + "SET default_file = ? " + "WHERE item_id = ? " + "AND default_file = ? "); pst.setBoolean(1, true); pst.setInt(2, id); pst.setBoolean(3, false); pst.execute(); pst.close(); }
From source file:org.latticesoft.util.resource.dao.Param.java
private void setValueToStatement(Object o, PreparedStatement pstmt) throws SQLException { if (log.isDebugEnabled()) { log.debug(this.sqlIndex + "=" + o); }/*from w w w . j a v a 2s . co m*/ switch (this.sqlType) { case Types.VARCHAR: case Types.CHAR: String s = (String) o; pstmt.setString(this.sqlIndex, s); break; case Types.BOOLEAN: if (o != null && o instanceof Boolean) { boolean b = ((Boolean) o).booleanValue(); pstmt.setBoolean(this.sqlIndex, b); } break; case Types.INTEGER: if (o != null && o instanceof Integer) { int i = ((Integer) o).intValue(); pstmt.setInt(this.sqlIndex, i); } break; case Types.SMALLINT: if (o != null && o instanceof Short) { short ss = ((Short) o).shortValue(); pstmt.setShort(this.sqlIndex, ss); } break; case Types.TINYINT: if (o != null && o instanceof Byte) { byte bb = ((Byte) o).byteValue(); pstmt.setByte(this.sqlIndex, bb); } break; case Types.BIGINT: if (o != null && o instanceof Long) { long l = ((Long) o).longValue(); pstmt.setLong(this.sqlIndex, l); } break; case Types.DOUBLE: if (o != null && o instanceof Double) { double dd = ((Double) o).doubleValue(); pstmt.setDouble(this.sqlIndex, dd); } break; case Types.FLOAT: if (o != null && o instanceof Float) { float f = ((Float) o).floatValue(); pstmt.setFloat(this.sqlIndex, f); } break; case Types.NUMERIC: if (o != null && o instanceof BigDecimal) { BigDecimal bd = (BigDecimal) o; pstmt.setBigDecimal(this.sqlIndex, bd); } break; case Types.TIMESTAMP: if (o != null && o instanceof Timestamp) { Timestamp ts = (Timestamp) o; pstmt.setTimestamp(this.sqlIndex, ts); } break; case Types.NULL: if (log.isDebugEnabled()) { log.debug(this.sqlIndex + " IS NULL"); } pstmt.setNull(this.sqlIndex, Types.NULL); break; default: if (o != null) { pstmt.setObject(this.sqlIndex, o); } } }
From source file:cz.lbenda.dataman.db.RowDesc.java
@SuppressWarnings("ConstantConditions") private <T> void putToPS(ColumnDesc columnDesc, T value, PreparedStatement ps, int position) throws SQLException { if (value == null) { ps.setObject(position, null);//from www .j av a2 s . co m return; } BinaryData bd = value instanceof BinaryData ? (BinaryData) value : null; switch (columnDesc.getDataType()) { case STRING: ps.setString(position, (String) value); break; case BOOLEAN: ps.setBoolean(position, (Boolean) value); break; case TIMESTAMP: ps.setTimestamp(position, (Timestamp) value); break; case DATE: ps.setDate(position, (Date) value); break; case TIME: ps.setTime(position, (Time) value); break; case BYTE: ps.setByte(position, (Byte) value); break; case SHORT: ps.setShort(position, (Short) value); break; case INTEGER: ps.setInt(position, (Integer) value); break; case LONG: ps.setLong(position, (Long) value); break; case FLOAT: ps.setFloat(position, (Float) value); break; case DOUBLE: ps.setDouble(position, (Double) value); break; case DECIMAL: ps.setBigDecimal(position, (BigDecimal) value); break; case UUID: ps.setBytes(position, AbstractHelper.uuidToByteArray((UUID) value)); break; case ARRAY: throw new UnsupportedOperationException("The saving changes in ARRAY isn't supported."); // ps.setArray(position, (Array) value); break; // FIXME the value isn't in type java.sql.Array case BYTE_ARRAY: if (bd == null || bd.isNull()) { ps.setBytes(position, null); } else { try { ps.setBytes(position, IOUtils.toByteArray(bd.getInputStream())); } catch (IOException e) { throw new SQLException(e); } } break; case CLOB: if (bd == null || bd.isNull()) { ps.setNull(position, Types.CLOB); } else { ps.setClob(position, bd.getReader()); } break; case BLOB: if (bd == null || bd.isNull()) { ps.setNull(position, Types.BLOB); } else { ps.setBlob(position, bd.getInputStream()); } break; case OBJECT: ps.setObject(position, value); } }
From source file:org.cloudfoundry.identity.uaa.scim.JdbcScimUserProvisioning.java
@Override public ScimUser createUser(final ScimUser user, final String password) throws InvalidPasswordException, InvalidUserException { passwordValidator.validate(password, user); validate(user);//from w w w . j a va2s. co m logger.info("Creating new user: " + user.getUserName()); final String id = UUID.randomUUID().toString(); try { jdbcTemplate.update(CREATE_USER_SQL, new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { ps.setString(1, id); ps.setInt(2, user.getVersion()); ps.setTimestamp(3, new Timestamp(new Date().getTime())); ps.setTimestamp(4, new Timestamp(new Date().getTime())); ps.setString(5, user.getUserName()); ps.setString(6, user.getPrimaryEmail()); ps.setString(7, user.getName().getGivenName()); ps.setString(8, user.getName().getFamilyName()); ps.setBoolean(9, user.isActive()); ps.setLong(10, UaaAuthority.fromUserType(user.getUserType()).value()); String phoneNumber = extractPhoneNumber(user); ps.setString(11, phoneNumber); ps.setString(12, passwordEncoder.encode(password)); } }); } catch (DuplicateKeyException e) { throw new UserAlreadyExistsException( "Username already in use (could be inactive account): " + user.getUserName()); } return retrieveUser(id); }
From source file:edu.northwestern.bioinformatics.studycalendar.domain.tools.hibernate.ScheduledActivityStateType.java
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException { ScheduledActivityState toSet = (ScheduledActivityState) value; Timestamp date = null;/*from w w w .jav a 2s .c o m*/ String reason = null; ScheduledActivityMode mode = null; Boolean withTime = false; if (toSet != null) { mode = toSet.getMode(); reason = toSet.getReason(); Date dateToSet = toSet.getDate(); date = dateToSet == null ? null : new Timestamp(dateToSet.getTime()); if (toSet.getWithTime()) { withTime = true; } } HibernateTypeUtils.logBind(log, index + DATE_INDEX, date); st.setTimestamp(index + DATE_INDEX, date); HibernateTypeUtils.logBind(log, index + WITH_TIME_INDEX, withTime); st.setBoolean(index + WITH_TIME_INDEX, withTime); HibernateTypeUtils.logBind(log, index + REASON_INDEX, reason); st.setString(index + REASON_INDEX, reason); MODE_TYPE.nullSafeSet(st, mode, index + MODE_INDEX, session); }
From source file:com.sinet.gage.dao.DomainsRepository.java
/** * /* w ww.j a v a 2s. c o m*/ * @param domains */ public void updateDomains(List<Domain> domains) { try { jdbcTemplate.batchUpdate(DOMAINS_FULL_UPDATE_SQL, new BatchPreparedStatementSetter() { public int getBatchSize() { if (domains == null) return 0; return domains.size(); } @Override public void setValues(PreparedStatement ps, int i) throws SQLException { Domain domain = domains.get(i); ps.setObject(1, domain.getGuid()); ps.setString(2, domain.getDomainName()); ps.setString(3, domain.getLoginPrefix()); ps.setLong(4, domain.getFlag()); ps.setString(5, domain.getDomainType()); ps.setLong(6, domain.getParentDomainId()); ps.setString(7, domain.getParentDomainName()); ps.setLong(8, domain.getStateDomainId()); ps.setString(9, domain.getStateDomainName()); ps.setString(10, domain.getLicenseType()); ps.setString(11, domain.getLicensePoolType()); ps.setInt(12, domain.getNoOfLicense()); ps.setBoolean(13, domain.isPilot()); ps.setDate(14, domain.getPilotStartDate()); ps.setDate(15, domain.getPilotEndDate()); ps.setBoolean(16, domain.isFullSubscription()); ps.setObject(17, domain.getSubscriptionStartDate()); ps.setObject(18, domain.getSubscriptionEndDate()); ps.setLong(19, domain.getModifierUserId()); ps.setTimestamp(20, domain.getModifiedDate()); ps.setLong(21, domain.getDomainId()); } }); } catch (Exception e) { log.error("Error in updating Domains", e); } }