List of usage examples for java.sql ResultSet getLong
long getLong(String columnLabel) throws SQLException;
ResultSet
object as a long
in the Java programming language. From source file:com.flexive.core.storage.MySQL.MySQLSequencerStorage.java
/** * {@inheritDoc}/* ww w . ja v a 2 s.co m*/ */ @Override public List<CustomSequencer> getCustomSequencers() throws FxApplicationException { List<CustomSequencer> res = new ArrayList<CustomSequencer>(20); Connection con = null; PreparedStatement ps = null; try { con = Database.getDbConnection(); ps = con.prepareStatement(SQL_GET_USER); ResultSet rs = ps.executeQuery(); while (rs != null && rs.next()) res.add(new CustomSequencer(rs.getString(1), rs.getBoolean(2), rs.getLong(3))); } catch (SQLException exc) { throw new FxDbException(LOG, exc, "ex.db.sqlError", exc.getMessage()); } finally { Database.closeObjects(MySQLSequencerStorage.class, con, ps); } return res; }
From source file:com.cedarsoftware.ncube.NCubeManager.java
/** * Retrieve all n-cubes that have a name that matches the SQL like statement, within the specified app, status, * version, and system date./*from w w w.ja v a2s . c o m*/ */ public static Object[] getNCubes(Connection connection, String app, String version, String status, String sqlLike, Date sysDate) { validate(connection, app, version); validateStatus(status); if (sqlLike == null) { sqlLike = "%"; } if (sysDate == null) { sysDate = new Date(); } PreparedStatement stmt = null; try { java.sql.Date systemDate = new java.sql.Date(sysDate.getTime()); stmt = connection.prepareStatement( "SELECT n_cube_id, n_cube_nm, notes_bin, version_no_cd, status_cd, app_cd, create_dt, update_dt, " + "create_hid, update_hid, sys_effective_dt, sys_expiration_dt, business_effective_dt, business_expiration_dt FROM n_cube WHERE n_cube_nm LIKE ? AND app_cd = ? AND version_no_cd = ? AND status_cd = ? AND sys_effective_dt <= ? AND (sys_expiration_dt IS NULL OR sys_expiration_dt >= ?)"); stmt.setString(1, sqlLike); stmt.setString(2, app); stmt.setString(3, version); stmt.setString(4, status); stmt.setDate(5, systemDate); stmt.setDate(6, systemDate); ResultSet rs = stmt.executeQuery(); List<NCubeInfoDto> records = new ArrayList<NCubeInfoDto>(); while (rs.next()) { NCubeInfoDto dto = new NCubeInfoDto(); dto.id = Long.toString(rs.getLong("n_cube_id")); dto.name = rs.getString("n_cube_nm"); byte[] notes = rs.getBytes("notes_bin"); dto.notes = new String(notes == null ? "".getBytes() : notes, "UTF-8"); dto.version = rs.getString("version_no_cd"); dto.status = rs.getString("status_cd"); dto.app = rs.getString("app_cd"); dto.createDate = rs.getDate("create_dt"); dto.updateDate = rs.getDate("update_dt"); dto.createHid = rs.getString("create_hid"); dto.updateHid = rs.getString("update_hid"); dto.sysEffDate = rs.getDate("sys_effective_dt"); dto.sysEndDate = rs.getDate("sys_expiration_dt"); dto.bizEffDate = rs.getDate("business_effective_dt"); dto.bizExpDate = rs.getDate("business_expiration_dt"); records.add(dto); } return records.toArray(); } catch (Exception e) { String s = "Unable to fetch NCubes matching '" + sqlLike + "' from database"; LOG.error(s, e); throw new RuntimeException(s, e); } finally { jdbcCleanup(stmt); } }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskXMsgClient.CFAsteriskXMsgClientSchema.java
public static Long getNullableUInt32(ResultSet reader, int colidx) { try {//from w w w . ja v a 2s . com long val = reader.getLong(colidx); if (reader.wasNull()) { return (null); } else { return (new Long(val)); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(CFAsteriskXMsgClientSchema.class, "getNullableUInt32", e); } }
From source file:eionet.cr.dao.readers.UploadDTOReader.java
public void readRow(ResultSet rs) throws SQLException, ResultSetReaderException { String subjectUri = rs.getString("URI"); UploadDTO uploadDTO = uploadsMap.get(subjectUri); if (uploadDTO == null) { uploadDTO = new UploadDTO(subjectUri); uploadsMap.put(subjectUri, uploadDTO); }/*from w w w . ja v a 2 s. c om*/ long predicateHash = rs.getLong("PREDICATE"); String objectValue = rs.getString("OBJECT"); if (predicateHash == LABEL_HASH) { uploadDTO.setLabel(objectValue); } else if (predicateHash == LAST_MODIFIED_HASH) { uploadDTO.setDateModified(objectValue); } else if (predicateHash == DC_TITLE_HASH) { // label not yet set, prefer dc:title as the label if (StringUtils.isBlank(uploadDTO.getLabel())) { uploadDTO.setLabel(objectValue); } } }
From source file:com.bt.aloha.batchtest.PerformanceMeasurmentDao.java
@SuppressWarnings("unchecked") public List<Metrics> findMetricsByRunId(long runId) { if (!exists) { log.warn("record skipped as schema does not exists"); return null; }//from w w w . j a v a 2s. com List<Metrics> metrics = null; try { metrics = jdbcTemplate.query("select unitPerSecond, averageDuration," + "numberOfRuns, numberOfSuccessfulRuns, variance, standardDeviation, success, description, threadInfo, testType " + "from Performance where runId=?", new Object[] { runId }, new RowMapper() { public Object mapRow(ResultSet rs, int row) throws SQLException { double ups = rs.getDouble("unitPerSecond"); double ad = rs.getDouble("averageDuration"); long nor = rs.getLong("numberOfRuns"); long nosr = rs.getLong("numberOfSuccessfulRuns"); double v = rs.getDouble("variance"); double sd = rs.getDouble("standardDeviation"); boolean s = rs.getBoolean("success"); String d = rs.getString("description"); String ti = rs.getString("threadInfo"); String tt = rs.getString("testType"); Metrics m = new Metrics(tt, ups, ad, nor, nosr, v, sd, s, d); m.setThreadInfo(ti); return m; } }); } catch (DataAccessException e) { log.error("Unable to access data for runId: " + runId, e); } return metrics; }
From source file:de.ingrid.importer.udk.strategy.v1.IDCStrategy1_0_4_fixInspireThemes.java
/** analyze all object searchterms and assign fitting INSPIRE themes */ private void updateInspireThemesOfObjects(HashMap<Integer, Long> themeIdToSearchtermId) throws Exception { if (log.isInfoEnabled()) { log.info("Updating INSPIRE Themes of objects..."); }//w w w . jav a2 s.c o m // all INSPIRE themes of object ordered by LINE asc String psSql = "SELECT termObj.line, val.entry_id " + "FROM searchterm_obj termObj, searchterm_value val " + "WHERE termObj.searchterm_id = val.id " + "and val.type = 'I' " + "and termObj.obj_id = ? " + "order by termObj.line"; PreparedStatement psReadObjInspireTerms = jdbc.prepareStatement(psSql); // insert INSPIRE theme into searchterm_value psSql = "INSERT INTO searchterm_value " + "(id, type, term, entry_id) " + "VALUES " + "(?, 'I', ?, ?)"; PreparedStatement psInsertTerm = jdbc.prepareStatement(psSql); // connect INSPIRE theme with object (insert searchterm_obj) psSql = "INSERT INTO searchterm_obj " + "(id, obj_id, line, searchterm_id) " + "VALUES " + "(?, ?, ?, ?)"; PreparedStatement psInsertTermObj = jdbc.prepareStatement(psSql); // remove INSPIRE theme from object psSql = "DELETE FROM searchterm_obj " + "WHERE obj_id=? " + "and searchterm_id=?"; PreparedStatement psRemoveTermObj = jdbc.prepareStatement(psSql); // here we track ids of assigned INSPIRE themes of current object Set<Integer> currThemeIds = new HashSet<Integer>(); int currLine = 0; long currObjId = -1; String currObjUuid = null; String currObjWorkState = null; // iterate over all searchterms applied to objects ordered by object String sqlAllObjTerms = "SELECT termObj.obj_id, val.term, obj.obj_uuid, obj.work_state " + "FROM t01_object obj, searchterm_obj termObj, searchterm_value val " + "WHERE obj.id = termObj.obj_id " + "and termObj.searchterm_id = val.id " + "order by termObj.obj_id"; Statement st = jdbc.createStatement(); ResultSet rs = jdbc.executeQuery(sqlAllObjTerms, st); while (rs.next()) { long readObjId = rs.getLong("obj_id"); // check whether object changed if (readObjId != currObjId) { // object changed ! // "finish" former object if (currObjId != -1) { // remove former "NO INSPIRE THEME" if new theme was added ! if (currThemeIds.size() > 1 && currThemeIds.contains(UtilsInspireThemes.noInspireThemeId)) { removeInspireThemeFromObject(UtilsInspireThemes.noInspireThemeId, currObjId, themeIdToSearchtermId, psRemoveTermObj, currThemeIds, currObjUuid, currObjWorkState); } // check whether former object has INSPIRE Theme, else add "NO INSPIRE THEME" if (currThemeIds.isEmpty()) { addInspireThemeToObject(UtilsInspireThemes.noInspireThemeId, currObjId, 1, themeIdToSearchtermId, psInsertTerm, psInsertTermObj, currThemeIds, null, currObjUuid, currObjWorkState); } } // process "new" object currObjId = readObjId; // needed for logging currObjUuid = rs.getString("obj_uuid"); currObjWorkState = rs.getString("work_state"); currLine = 0; currThemeIds.clear(); // fetch all assigned INSPIRE themes and max line psReadObjInspireTerms.setLong(1, currObjId); ResultSet rsObjInspireTerms = psReadObjInspireTerms.executeQuery(); while (rsObjInspireTerms.next()) { currLine = rsObjInspireTerms.getInt("line"); Integer entryId = rsObjInspireTerms.getInt("entry_id"); currThemeIds.add(entryId); } rsObjInspireTerms.close(); } // analyze read searchterm. Check whether contains inspire term ! // add according INSPIRE themes if not added yet ! // read searchterm, lower case for comparison String searchTerm = rs.getString("term"); Set<Integer> newThemeIds = UtilsInspireThemes.getThemeIdsOfTerm(searchTerm, null); for (Integer newThemeId : newThemeIds) { if (!currThemeIds.contains(newThemeId)) { addInspireThemeToObject(newThemeId, currObjId, ++currLine, themeIdToSearchtermId, psInsertTerm, psInsertTermObj, currThemeIds, searchTerm, currObjUuid, currObjWorkState); } } } rs.close(); st.close(); psReadObjInspireTerms.close(); psInsertTerm.close(); psInsertTermObj.close(); psRemoveTermObj.close(); if (log.isInfoEnabled()) { log.info("Updating INSPIRE Themes of objects... done"); } }
From source file:desktop.olayinka.file.transfer.model.DerbyJDBCHelper.java
public void onStart(Connection mConnection) { Statement statement = null;/*from ww w .jav a 2 s. c om*/ ResultSet resultSet = null; try { statement = mConnection.createStatement(); resultSet = statement.executeQuery("SELECT * FROM app_info"); resultSet.next(); mCurrentVersion = resultSet.getLong(1); cleanUp(statement, resultSet); } catch (SQLException e) { e.printStackTrace(); cleanUp(statement, resultSet); try { statement = mConnection.createStatement(); InputStream in = DerbyJDBCHelper.class.getResourceAsStream("/raw/db.sql"); String[] queries = IOUtils.toString(in).split(";"); for (String query : queries) { query = query.trim(); if (!query.isEmpty()) { statement.execute(query); } } mConnection.commit(); mCurrentVersion = 1; cleanUp(statement, null); } catch (SQLException | IOException e1) { e1.printStackTrace(); cleanUp(statement, null); System.exit(1); } } }
From source file:com.grayfox.server.dao.jdbc.RecommendationJdbcDao.java
@Override public List<Recommendation> findNearestByCategoriesLiked(String accessToken, Location location, Integer radius, Locale locale) {/*from w w w. j a v a 2 s. c om*/ Set<String> categoryNames = new HashSet<>(); List<Recommendation> recommendations = getJdbcTemplate() .query(getQuery("Recommendation.findNearestByCategoriesLiked", locale), (ResultSet rs, int i) -> { String categoryName = rs.getString(7); if (categoryNames.add(categoryName)) { Recommendation recommendation = new Recommendation(); Poi poi = new Poi(); int columnIndex = 1; poi.setId(rs.getLong(columnIndex++)); poi.setName(rs.getString(columnIndex++)); poi.setLocation(new Location()); poi.getLocation().setLatitude(rs.getDouble(columnIndex++)); poi.getLocation().setLongitude(rs.getDouble(columnIndex++)); poi.setFoursquareId(rs.getString(columnIndex++)); poi.setFoursquareRating(rs.getDouble(columnIndex++)); recommendation.setType(Recommendation.Type.SELF); recommendation.setReason(Messages.get("recommendation.self.reason", locale, categoryName)); recommendation.setPoi(poi); return recommendation; } else return null; }, accessToken, location.getLatitude(), location.getLongitude(), radius); recommendations = recommendations.stream().filter(Objects::nonNull).collect(Collectors.toList()); recommendations.forEach(recommendation -> recommendation.getPoi().setCategories(new HashSet<>( categoryDao.findByPoiFoursquareId(recommendation.getPoi().getFoursquareId(), locale)))); return recommendations; }
From source file:com.hs.mail.imap.dao.MySqlSearchDao.java
private List<Long> query(UidToMsnMapper map, long mailboxID, String name, final String pattern) { if (StringUtils.isEmpty(pattern)) { String sql = SearchQuery.toQuery(mailboxID, name, true); return getJdbcTemplate().queryForList(sql, Long.class); } else {//from w ww . j ava2 s .c o m String sql = SearchQuery.toQuery(mailboxID, name, false); final List<Long> results = new ArrayList<Long>(); getJdbcTemplate().query(sql, new RowCallbackHandler() { public void processRow(ResultSet rs) throws SQLException { // Stored header values are not decoded. String value = DecoderUtil.decodeEncodedWords(rs.getString(2)); if (StringUtils.contains(value, pattern)) { results.add(rs.getLong(1)); } } }); return results; } }
From source file:com.healthcit.cacure.utils.DBSchemaUpdater.java
@Override public void afterPropertiesSet() throws Exception { Connection connection = DataSourceUtils.getConnection(dataSource); connection.setAutoCommit(false);//w ww.j a v a 2 s . c o m try { Statement statement = connection.createStatement(); try { long version = 0; try { ResultSet rs = statement.executeQuery("select schema_version from sys_variables limit 1;"); try { if (!rs.next()) { throw new RuntimeException("Seems there is no any row in sys_variables table."); } version = rs.getLong(1); } finally { rs.close(); } } catch (PSQLException e) { // it's needed for executing more scripts successfully connection.rollback(); log.info("Can't find sys_variables tables. Appling initial script."); String initialScriptStatements = getStatementsFor(0); if (initialScriptStatements == null) { throw new RuntimeException("Can't find initial script."); } statement.executeUpdate(initialScriptStatements); //there is already schema_version at 0 connection.commit(); log.info("Initial script succesfully executed."); } for (long v = version + 1;; v++) { String statements = getStatementsFor(v); if (statements == null) { break; } log.info("Updating schema to " + v + " version..."); statement.execute(statements); statement.executeUpdate("update sys_variables set schema_version = " + v + ";"); connection.commit(); log.info("OK"); } } catch (BatchUpdateException e) { if (e.getNextException() != null) { e.getNextException().printStackTrace(); } e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); connection.rollback(); } finally { statement.close(); } } finally { DataSourceUtils.releaseConnection(connection, dataSource); } }