List of usage examples for java.sql ResultSet getBoolean
boolean getBoolean(String columnLabel) throws SQLException;
ResultSet
object as a boolean
in the Java programming language. From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstPgSql.CFAstPgSqlSecUserTable.java
public void deleteSecUserByUEMailIdx(CFAstAuthorization Authorization, String argEMailAddress) { final String S_ProcName = "deleteSecUserByUEMailIdx"; ResultSet resultSet = null; try {/*from ww w .j a va2s. c o m*/ Connection cnx = schema.getCnx(); String sql = "SELECT " + schema.getLowerSchemaDbName() + ".sp_delete_secuser_by_uemailidx( ?, ?, ?, ?, ?" + ", " + "?" + " ) as DeletedFlag"; if (stmtDeleteByUEMailIdx == null) { stmtDeleteByUEMailIdx = cnx.prepareStatement(sql); } int argIdx = 1; stmtDeleteByUEMailIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByUEMailIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtDeleteByUEMailIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtDeleteByUEMailIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByUEMailIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtDeleteByUEMailIdx.setString(argIdx++, argEMailAddress); resultSet = stmtDeleteByUEMailIdx.executeQuery(); if (resultSet.next()) { boolean deleteFlag = resultSet.getBoolean(1); if (resultSet.next()) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response"); } } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected 1 record result set to be returned by delete, not 0 rows"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }
From source file:com.flexive.core.storage.genericSQL.GenericEnvironmentLoader.java
private Map<Long, List<FxStructureOption>> loadAllOptions(Connection con, String idColumn, String whereClause, String table) throws SQLException { Statement stmt = null;/*from ww w . j av a 2 s. co m*/ Map<Long, List<FxStructureOption>> result = new HashMap<Long, List<FxStructureOption>>(500); try { stmt = con.createStatement(); final ResultSet rs = stmt.executeQuery("SELECT " + idColumn + ",OPTKEY,MAYOVERRIDE,ISINHERITED,OPTVALUE FROM " + table + " WHERE " + whereClause); final Map<String, String> cachedKeys = Maps.newHashMap(); while (rs.next()) { final long id = rs.getLong(1); if (!result.containsKey(id)) { result.put(id, new ArrayList<FxStructureOption>()); } final String dbValue = cachedString(cachedKeys, rs.getString(5)); final String value; if (FxStructureOption.VALUE_FALSE.equals(dbValue)) { // check string constants to avoid creating "0" and "1" strings all over the place value = FxStructureOption.VALUE_FALSE; } else if (FxStructureOption.VALUE_TRUE.equals(dbValue)) { value = FxStructureOption.VALUE_TRUE; } else { value = dbValue; } FxStructureOption.setOption(result.get(id), cachedString(cachedKeys, rs.getString(2)), rs.getBoolean(3), rs.getBoolean(4), value); } return result; } finally { Database.closeObjects(GenericEnvironmentLoader.class, null, stmt); } }
From source file:com.alfaariss.oa.engine.session.jdbc.JDBCSessionFactory.java
/** * Retrieve the Session with the given id. * @param id The Session id.//from w w w .j a v a 2s .co m * @return The Session, or null if a Session with the given id does not exist. * @throws PersistenceException If retrieving fails. */ @SuppressWarnings("unchecked") //Serialize value can not be checked public JDBCSession retrieve(Object id) throws PersistenceException { if (id == null || !(id instanceof String)) throw new IllegalArgumentException("Suplied id is empty or invalid"); Connection oConnection = null; JDBCSession session = null; PreparedStatement ps = null; ResultSet rs = null; try { oConnection = _oDataSource.getConnection(); ps = oConnection.prepareStatement(_sSearchQuery); ps.setString(1, (String) id); rs = ps.executeQuery(); if (rs.next()) { session = new JDBCSession(this, rs.getString(_sColumnREQUESTOR)); session.setId((String) id); String sTGTID = rs.getString(_sColumnTGT_ID); if (sTGTID != null) session.setTGTId(sTGTID); session.setState(SessionState.values()[rs.getInt(_sColumnSTATE)]); String sUrl = rs.getString(_sColumnURL); if (sUrl != null) session.setProfileURL(sUrl); IUser oUser = (IUser) Serialize.decode(rs.getBytes(_sColumnOWNER)); if (oUser != null) session.setUser(oUser); session.setExpTime(rs.getTimestamp(_sColumnEXPIRATION).getTime()); session.setForcedAuthentication(rs.getBoolean(_sColumnFORCED_AUTHENTICATE)); session.setPassive(rs.getBoolean(_sColumnPASSIVE)); SessionAttributes oAttributes = (SessionAttributes) Serialize .decode(rs.getBytes(_sColumnATTRIBUTES)); if (oAttributes != null) session.setAttributes(oAttributes); String sForcedUid = rs.getString(_sColumnFORCED_USERID); if (sForcedUid != null) session.setForcedUserID(sForcedUid); Locale oLocale = (Locale) Serialize.decode(rs.getBytes(_sColumnLOCALE)); if (oLocale != null) session.setLocale(oLocale); List listProfiles = (List) Serialize.decode(rs.getBytes(_sColumnAUTHN_PROFILES)); if (listProfiles != null) session.setAuthNProfiles(listProfiles); AuthenticationProfile oProfile = (AuthenticationProfile) Serialize .decode(rs.getBytes(_sColumnSELECTED_AUTHN_PROFILE)); if (oProfile != null) session.setSelectedAuthNProfile(oProfile); } } catch (SQLException e) { _logger.error("Could not execute search query: " + _sSearchQuery, e); throw new PersistenceException(SystemErrors.ERROR_RESOURCE_RETRIEVE); } catch (ClassCastException e) { _logger.error("Could not decode, invalid class type", e); throw new PersistenceException(SystemErrors.ERROR_RESOURCE_RETRIEVE); } catch (Exception e) { _logger.error("Internal error during retrieve of session id: " + id, e); throw new PersistenceException(SystemErrors.ERROR_RESOURCE_RETRIEVE); } finally { try { if (rs != null) rs.close(); } catch (SQLException e) { _logger.debug("Could not close resultset", e); } try { if (ps != null) ps.close(); } catch (SQLException e) { _logger.debug("Could not close statement", e); } try { if (oConnection != null) oConnection.close(); } catch (SQLException e) { _logger.debug("Could not close connection", e); } } return session; }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskPgSql.CFAsteriskPgSqlSecDeviceTable.java
public void deleteSecDeviceByUserIdx(CFSecurityAuthorization Authorization, UUID argSecUserId) { final String S_ProcName = "deleteSecDeviceByUserIdx"; ResultSet resultSet = null; try {//w ww .j a v a2 s. co m Connection cnx = schema.getCnx(); String sql = "SELECT " + schema.getLowerDbSchemaName() + ".sp_delete_secdev_by_useridx( ?, ?, ?, ?, ?" + ", " + "?" + " ) as DeletedFlag"; if (stmtDeleteByUserIdx == null) { stmtDeleteByUserIdx = cnx.prepareStatement(sql); } int argIdx = 1; stmtDeleteByUserIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByUserIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtDeleteByUserIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtDeleteByUserIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByUserIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtDeleteByUserIdx.setString(argIdx++, argSecUserId.toString()); resultSet = stmtDeleteByUserIdx.executeQuery(); if (resultSet.next()) { boolean deleteFlag = resultSet.getBoolean(1); if (resultSet.next()) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response"); } } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected 1 record result set to be returned by delete, not 0 rows"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }
From source file:com.draagon.meta.manager.db.driver.GenericSQLDriver.java
protected void parseField(Object o, MetaField f, ResultSet rs, int j) throws SQLException { switch (f.getType()) { case MetaField.BOOLEAN: { boolean bv = rs.getBoolean(j); if (rs.wasNull()) { f.setBoolean(o, null);/*from w ww . j ava 2 s . c om*/ } else { f.setBoolean(o, new Boolean(bv)); } } break; case MetaField.BYTE: { byte bv = rs.getByte(j); if (rs.wasNull()) { f.setByte(o, null); } else { f.setByte(o, new Byte(bv)); } } break; case MetaField.SHORT: { short sv = rs.getShort(j); if (rs.wasNull()) { f.setShort(o, null); } else { f.setShort(o, new Short(sv)); } } break; case MetaField.INT: { int iv = rs.getInt(j); if (rs.wasNull()) { f.setInt(o, null); } else { f.setInt(o, new Integer(iv)); } } break; case MetaField.DATE: { Timestamp tv = rs.getTimestamp(j); if (rs.wasNull()) { f.setDate(o, null); } else { f.setDate(o, new java.util.Date(tv.getTime())); } } break; case MetaField.LONG: { long lv = rs.getLong(j); if (rs.wasNull()) { f.setLong(o, null); } else { f.setLong(o, new Long(lv)); } } break; case MetaField.FLOAT: { float fv = rs.getFloat(j); if (rs.wasNull()) { f.setFloat(o, null); } else { f.setFloat(o, new Float(fv)); } } break; case MetaField.DOUBLE: { double dv = rs.getDouble(j); if (rs.wasNull()) { f.setDouble(o, null); } else { f.setDouble(o, new Double(dv)); } } break; case MetaField.STRING: f.setString(o, rs.getString(j)); break; case MetaField.OBJECT: f.setObject(o, rs.getObject(j)); break; } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_1.CFAstPgSql.CFAstPgSqlSecDeviceTable.java
public void deleteSecDeviceByUserIdx(CFAstAuthorization Authorization, UUID argSecUserId) { final String S_ProcName = "deleteSecDeviceByUserIdx"; ResultSet resultSet = null; try {/* w ww .jav a 2 s . com*/ Connection cnx = schema.getCnx(); String sql = "SELECT " + schema.getLowerDbSchemaName() + ".sp_delete_secdev_by_useridx( ?, ?, ?, ?, ?" + ", " + "?" + " ) as DeletedFlag"; if (stmtDeleteByUserIdx == null) { stmtDeleteByUserIdx = cnx.prepareStatement(sql); } int argIdx = 1; stmtDeleteByUserIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByUserIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtDeleteByUserIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtDeleteByUserIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByUserIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtDeleteByUserIdx.setString(argIdx++, argSecUserId.toString()); resultSet = stmtDeleteByUserIdx.executeQuery(); if (resultSet.next()) { boolean deleteFlag = resultSet.getBoolean(1); if (resultSet.next()) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response"); } } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected 1 record result set to be returned by delete, not 0 rows"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }
From source file:edu.umd.cs.marmoset.modelClasses.Project.java
/** * Populate a Submission from a ResultSet that is positioned * at a row of the submissions table.//from w w w . j ava 2 s . co m * * @param resultSet the ResultSet containing the row data * @param startingFrom index specifying where to start fetching attributes from; * useful if the row contains attributes from multiple tables */ public void fetchValues(ResultSet resultSet, int startingFrom) throws SQLException { setProjectPK(Project.asPK(SqlUtilities.getInteger(resultSet, startingFrom++))); setCoursePK(Course.asPK(resultSet.getInt(startingFrom++))); setTestSetupPK(resultSet.getInt(startingFrom++)); setDiffAgainst(Project.asPK(resultSet.getInt(startingFrom++))); setProjectNumber(resultSet.getString(startingFrom++)); setOntime(resultSet.getTimestamp(startingFrom++)); setLate(resultSet.getTimestamp(startingFrom++)); setTitle(resultSet.getString(startingFrom++)); setUrl(resultSet.getString(startingFrom++)); setDescription(resultSet.getString(startingFrom++)); setReleaseTokens(resultSet.getInt(startingFrom++)); setRegenerationTime(resultSet.getInt(startingFrom++)); setIsTested(resultSet.getBoolean(startingFrom++)); setPair(resultSet.getBoolean(startingFrom++)); setVisibleToStudents(resultSet.getBoolean(startingFrom++)); setPostDeadlineOutcomeVisibility(resultSet.getString(startingFrom++)); setKindOfLatePenalty(resultSet.getString(startingFrom++)); setLateMultiplier(resultSet.getDouble(startingFrom++)); setLateConstant(resultSet.getInt(startingFrom++)); setCanonicalStudentRegistrationPK(StudentRegistration.asPK(resultSet.getInt(startingFrom++))); setBestSubmissionPolicy(resultSet.getString(startingFrom++)); setReleasePolicy(resultSet.getString(startingFrom++)); setStackTracePolicy(resultSet.getString(startingFrom++)); // Using -1 to represent infinity int num = resultSet.getInt(startingFrom++); if (num == -1) num = Integer.MAX_VALUE; setNumReleaseTestsRevealed(num); setArchivePK(SqlUtilities.getInteger(resultSet, startingFrom++)); setBrowserEditing(BrowserEditing.valueOfAnyCase(resultSet.getString(startingFrom++))); }
From source file:com.wso2telco.gsma.authenticators.dao.impl.AttributeConfigDaoImpl.java
public UserConsentDetails getUserConsentDetails(UserConsentDetails userConsentDetails) throws NamingException, DBUtilException { Connection connection = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null; UserConsentDetails userConsent = null; String query = "SELECT usercon.consent_status as activestatus ,usercon.expire_time as consent_expire_time " + "FROM " + TableName.USER_CONSENT + " usercon INNER JOIN " + TableName.CONSENT + " con ON con" + ".consent_id = usercon" + ".consent_id INNER JOIN " + TableName.OPERATOR + " op ON op.operatorname=usercon.operator INNER JOIN " + TableName.SCOPE_PARAMETER + " scp ON scp" + ".param_id=con.scope_id WHERE op.operatorname=? AND scp.scope=? AND usercon.client_id=? AND usercon" + ".msisdn=?;"; try {//from w w w. j a v a 2 s .c om connection = getConnectDBConnection(); preparedStatement = connection.prepareStatement(query); preparedStatement.setString(1, userConsentDetails.getOperatorName()); preparedStatement.setString(2, userConsentDetails.getScope()); preparedStatement.setString(3, userConsentDetails.getConsumerKey()); preparedStatement.setString(4, userConsentDetails.getMsisdn()); if (log.isDebugEnabled()) { log.debug("Query in method getUserConsentDetails:" + preparedStatement); } resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { userConsent = new UserConsentDetails(); userConsent.setConsumerKey(userConsentDetails.getConsumerKey()); userConsent.setScope(userConsentDetails.getScope()); userConsent.setOperatorName(userConsentDetails.getOperatorName()); userConsent.setMsisdn(userConsentDetails.getMsisdn()); userConsent.setRevokeStatus(String.valueOf(resultSet.getBoolean("activestatus"))); userConsent.setConsentExpireDatetime(resultSet.getString("consent_expire_time")); } } catch (SQLException e) { log.error("Exception occurred while retrieving data to the database for consumerKey: " + userConsentDetails.getConsumerKey() + " and msisdn: " + userConsentDetails.getMsisdn() + " :" + e.getMessage()); throw new DBUtilException(e.getMessage(), e); } finally { IdentityDatabaseUtil.closeAllConnections(connection, resultSet, preparedStatement); } return userConsent; }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskPgSql.CFAsteriskPgSqlSysClusterTable.java
public void deleteSysCluster(CFSecurityAuthorization Authorization, CFSecuritySysClusterBuff Buff) { final String S_ProcName = "deleteSysCluster"; ResultSet resultSet = null; try {/*from ww w. j ava 2s. c om*/ Connection cnx = schema.getCnx(); int SingletonId = Buff.getRequiredSingletonId(); String sql = "SELECT " + schema.getLowerDbSchemaName() + ".sp_delete_sysclus( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + " ) as DeletedFlag"; if (stmtDeleteByPKey == null) { stmtDeleteByPKey = cnx.prepareStatement(sql); } int argIdx = 1; stmtDeleteByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByPKey.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtDeleteByPKey.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtDeleteByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtDeleteByPKey.setInt(argIdx++, SingletonId); stmtDeleteByPKey.setInt(argIdx++, Buff.getRequiredRevision()); ; resultSet = stmtDeleteByPKey.executeQuery(); if (resultSet.next()) { boolean deleteFlag = resultSet.getBoolean(1); if (resultSet.next()) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response"); } } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected 1 record result set to be returned by delete, not 0 rows"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }
From source file:fll.db.Queries.java
/** * Get the value of Bye for the given team number, tournament and run number * /* ww w. jav a 2 s .c o m*/ * @return true if the score is a bye, false if it's not a bye or the score * does not exist * @throws SQLException on a database error */ public static boolean isBye(final Connection connection, final int tournament, final int teamNumber, final int runNumber) throws SQLException, IllegalArgumentException { PreparedStatement prep = null; ResultSet rs = null; try { prep = getScoreStatsPrep(connection); prep.setInt(1, tournament); prep.setInt(2, teamNumber); prep.setInt(3, runNumber); rs = prep.executeQuery(); if (rs.next()) { return rs.getBoolean("Bye"); } else { return false; } } finally { SQLFunctions.close(rs); SQLFunctions.close(prep); } }