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:com.flexive.core.Database.java
/** * Loads all FxString entries stored in the given table. * * @param con an existing connection * @param table table to use// w ww . j a v a 2 s. co m * @param columns name of the columns containing the translations * @return all FxString entries stored in the given table, indexed by the ID field. * @throws SQLException if the query was not successful */ public static Map<Long, FxString[]> loadFxStrings(Connection con, String table, String... columns) throws SQLException { Statement stmt = null; final StringBuilder sql = new StringBuilder(); final Map<Long, FxString[]> result = Maps.newHashMap(); final Map<String, String> cache = Maps.newHashMap(); // avoid return duplicate strings try { sql.append("SELECT ID, LANG"); final boolean hasDefLang = columns.length == 1; // deflang is only meaningful for single-column tables if (hasDefLang) sql.append(", DEFLANG"); for (String column : columns) { sql.append(',').append(column); if (!hasDefLang) sql.append(',').append(column).append("_MLD"); } sql.append(" FROM ").append(table).append(ML).append(" ORDER BY LANG"); final int startIndex = hasDefLang ? 4 : 3; stmt = con.createStatement(); final ResultSet rs = stmt.executeQuery(sql.toString()); while (rs.next()) { final long id = rs.getLong(1); final int lang = rs.getInt(2); boolean defLang = false; if (hasDefLang) defLang = rs.getBoolean(3); if (lang == FxLanguage.SYSTEM_ID) { continue; // TODO how to deal with system language? } FxString[] entry = result.get(id); if (entry == null) { entry = new FxString[columns.length]; } for (int i = 0; i < columns.length; i++) { final String value = rs.getString(startIndex + i * (hasDefLang ? 1 : 2)); String translation = cache.get(value); // return cached string instance if (translation == null) { translation = value; cache.put(value, value); } if (entry[i] == null) entry[i] = new FxString(true, lang, translation); else entry[i].setTranslation(lang, translation); if (!hasDefLang) defLang = rs.getBoolean(startIndex + 1 + i * 2); if (defLang) entry[i].setDefaultLanguage(lang); } result.put(id, entry); } // canonicalize FxStrings (some tables, especially assignments, contain a lot of 100% identical labels for different IDs) final Map<FxString, FxString> fxCache = Maps.newHashMapWithExpectedSize(result.size() * 2); for (FxString[] values : result.values()) { for (int i = 0; i < values.length; i++) { final FxString value = values[i]; FxString cached = fxCache.get(value); if (cached != null) { values[i] = cached; } else { fxCache.put(value, value); } } } } finally { closeObjects(Database.class, null, stmt); } return result; }
From source file:net.sourceforge.vulcan.spring.jdbc.RequestUserQuery.java
@Override protected Object mapRow(ResultSet rs, int rowNumber) throws SQLException { final String value = rs.getString("requested_by"); if (rs.wasNull()) { return null; }/*from w ww. ja v a2s.c om*/ final boolean isScheduler = rs.getBoolean("scheduled_build"); if (isScheduler) { schedulers.add(value); } else { users.add(value); } return value; }
From source file:com.simpletasks.dao.impl.jdbc.TaskMapper.java
public Task mapRow(ResultSet resultSet, int i) throws SQLException { Task task = new Task(); task.setId(resultSet.getInt(1));/*from w w w . j a v a 2 s . c o m*/ task.setTitle(resultSet.getString(3)); task.setDetail(resultSet.getString(4)); task.setFinished(resultSet.getBoolean(5)); task.setCreateDate(DaoUtil.getDate(resultSet.getTimestamp(6))); task.setEndDate(DaoUtil.getDate(resultSet.getTimestamp(7))); return task; }
From source file:net.navasoft.madcoin.backend.services.security.ProvidernameMapper.java
/** * Map row./* ww w. ja v a2 s.co m*/ * * @param rs * the rs * @param arg1 * the arg1 * @return the user * @throws SQLException * the SQL exception * @since 18/08/2014, 04:36:22 PM */ @Override public User mapRow(ResultSet rs, int arg1) throws SQLException { String username = rs.getString(USER_COLUMN); return new User(username, rs.getString(PASSWORD_COLUMN), rs.getBoolean(ENABLED_COLUMN), true, true, true, getAuthorities(username)); }
From source file:ems.emsystem.dao.JDBCEmployeeDAOImpl.java
private Employee getEmployeeFromResultSet(ResultSet rs) throws SQLException { Employee em = new Employee(); em.setId(rs.getLong("ID")); em.setActive(rs.getBoolean("ACTIVE")); em.setBirthdate(rs.getDate("BIRTHDATE")); em.setFirstname(rs.getString("FIRSTNAME")); em.setLastname(rs.getString("LASTNAME")); em.setSalary(rs.getDouble("SALARY")); long dep_id = rs.getLong("DEPARTMENT"); Department dep = departmentDAO.getDepartment(dep_id); em.setDepartment(dep);/* ww w. j a v a 2s. c o m*/ return em; }
From source file:com.dai.jdbc.SelecaoTreinoExtractor.java
public SelecaoTreino extractData(ResultSet resultSet) throws SQLException, DataAccessException { SelecaoTreino st = new SelecaoTreino(); st.setIdUtilizador(resultSet.getInt("utilizador_idutilizador_st")); st.setIdTreino(resultSet.getInt("treino_idtreino")); st.setPresenca(resultSet.getBoolean("presenca")); st.setNome(resultSet.getString("nomeUtilizador_t")); return st;/* w w w . j ava2 s . co m*/ }
From source file:org.smigo.comment.JdbcCommentDao.java
@Override public List<Comment> getComments(String receiver) { return jdbcTemplate.query(SELECT, new Object[] { receiver }, new RowMapper<Comment>() { @Override//from w ww. jav a 2s. com public Comment mapRow(ResultSet rs, int rowNum) throws SQLException { return new Comment(rs.getInt("ID"), rs.getString("TEXT"), rs.getString("SUBMITTER"), rs.getInt("YEAR"), rs.getDate("CREATEDATE"), rs.getBoolean("UNREAD")); } }); }
From source file:edu.ku.brc.specify.dbsupport.TaskSemaphoreMgr.java
/** * Check to see if the lock is set on the task semaphore. * @param title The human (localized) title of the task * @param name the unique name//from w ww. jav a2 s . c o m * @param scope the scope of the lock * @return true if it is locked. */ public static boolean isLocked(final String title, final String name, final SCOPE scope) { Discipline discipline = scope == SCOPE.Discipline ? AppContextMgr.getInstance().getClassObject(Discipline.class) : null; Collection collection = scope == SCOPE.Collection ? AppContextMgr.getInstance().getClassObject(Collection.class) : null; Connection connection = DBConnection.getInstance().getConnection(); if (connection != null) { Statement stmt = null; ResultSet rs = null; try { String sql = buildSQL(name, scope, discipline, collection); //log.debug(sql); stmt = connection.createStatement(); rs = stmt.executeQuery(sql); if (rs != null && rs.next()) { return rs.getBoolean(1); } return false; } catch (Exception ex) { ex.printStackTrace(); //edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); //edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(TaskSemaphoreMgr.class, ex); //log.error(ex); } finally { try { if (rs != null) { rs.close(); } if (stmt != null) { stmt.close(); } } catch (Exception ex) { } } } return false; /* // This is not used right NOW! DataProviderSessionIFace session = null; try { session = DataProviderFactory.getInstance().createSession(); SpTaskSemaphore semaphore = getSemaphore(session, name, scope, discipline, collection); if (semaphore == null) { //throw new RuntimeException("lock ["+title+"] didn't exist"); return false; } return semaphore.getIsLocked(); } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(TaskSemaphoreMgr.class, ex); ex.printStackTrace(); //log.error(ex); } finally { if (session != null) { session.close(); } } throw new RuntimeException("Error checking lock ["+title+"]"); */ }
From source file:org.mayocat.cms.pages.store.jdbi.mapper.PageMapper.java
@Override public Page map(int index, ResultSet resultSet, StatementContext ctx) throws SQLException { Page page = new Page((UUID) resultSet.getObject("id")); if (resultSet.getObject("published") != null) { page.setPublished(resultSet.getBoolean("published")); }//from ww w. j ava 2s . c o m page.setTitle(resultSet.getString("title")); page.setSlug(resultSet.getString("slug")); page.setContent(resultSet.getString("content")); page.setFeaturedImageId((UUID) resultSet.getObject("featured_image_id")); if (!Strings.isNullOrEmpty(resultSet.getString("localization_data"))) { ObjectMapper mapper = new ObjectMapper(); try { Map<Locale, Map<String, Object>> localizedVersions = Maps.newHashMap(); Map[] data = mapper.readValue(resultSet.getString("localization_data"), Map[].class); for (Map map : data) { try { localizedVersions.put(LocaleUtils.toLocale((String) map.get("locale")), (Map) map.get("entity")); } catch (IllegalArgumentException e) { // Invalid locale, just ignore it } } page.setLocalizedVersions(localizedVersions); } catch (IOException e) { throw new SQLException("Failed to de-serialize localization JSON data", e); } } String model = resultSet.getString("model"); if (!Strings.isNullOrEmpty(model)) { page.setModel(model); } return page; }
From source file:com.oracle2hsqldb.dialect.GenericDialect.java
public Iterator getUniqueKeys(DataSource dataSource, final String schemaName) { final List result = new LinkedList(); MetaDataJdbcTemplate template = new MetaDataJdbcTemplate(dataSource) { protected ResultSet getResults(DatabaseMetaData metaData) throws SQLException { return metaData.getIndexInfo(null, schemaName, null, true, true); }// www. j a va 2s . co m }; template.query(new RowCallbackHandler() { public void processRow(ResultSet uniqueIndexes) throws SQLException { boolean isNonUnique = uniqueIndexes.getBoolean("NON_UNIQUE"); if (!isNonUnique) { String columnName = uniqueIndexes.getString("COLUMN_NAME"); String constraintName = uniqueIndexes.getString("INDEX_NAME"); String tableName = uniqueIndexes.getString("TABLE_NAME"); result.add(new UniqueConstraint.Spec(tableName, columnName, constraintName)); } } }); return result.iterator(); }