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:io.apiman.manager.api.jdbc.handlers.ResponseStatsPerClientHandler.java
/** * @see org.apache.commons.dbutils.ResultSetHandler#handle(java.sql.ResultSet) *//*from www . j a v a 2s . c o m*/ @Override public ResponseStatsPerClientBean handle(ResultSet rs) throws SQLException { ResponseStatsPerClientBean rval = new ResponseStatsPerClientBean(); while (rs.next()) { String client = rs.getString(1); if (client == null) { continue; } String rtype = rs.getString(2); long count = rs.getLong(3); ResponseStatsDataPoint dataPoint = rval.getData().get(client); if (dataPoint == null) { dataPoint = new ResponseStatsDataPoint(); rval.getData().put(client, dataPoint); } if (rtype == null) { dataPoint.setTotal(dataPoint.getErrors() + dataPoint.getFailures() + count); } else if (rtype.equals("failure")) { //$NON-NLS-1$ dataPoint.setTotal(dataPoint.getTotal() + count); dataPoint.setFailures(count); } else if (rtype.equals("error")) { //$NON-NLS-1$ dataPoint.setTotal(dataPoint.getTotal() + count); dataPoint.setErrors(count); } } return rval; }
From source file:com.springsource.greenhouse.events.load.JdbcEventLoaderRepositoryTest.java
@Test public void updateEventSession() throws SQLException { long eventId = eventLoaderRepository.loadEvent( new EventData(1, "Test Event", "Test Event Description", "test", "2012-10-15T00:00:00", "2012-10-18T23:59:59", "America/New_York", "NFJS", 297), new VenueData("Some Fancy Hotel", "1234 North Street, Chicago, IL 60605", 41.89001, -87.677765, "It's in Illinois")); long timeSlotId = eventLoaderRepository.loadTimeSlot(new TimeSlotData(eventId, "Time Slot 1", "2012-10-15T00:00:00", "2012-10-18T23:59:59", "NFJS", 6296)); int eventSessionId = 1; List<Long> leaderIds = Collections.emptyList(); eventLoaderRepository.loadEventSession(new EventSessionData(eventId, eventSessionId, "What's new in Spring", "Come find out what's new in Spring", "#newspring", 1L, timeSlotId, "NFJS", 24409L, leaderIds)); jdbcTemplate.queryForObject(//from w w w . j av a 2 s . c o m "select event, id, title, description, hashtag, venue, timeslot from EventSession where event=? and id=?", new RowMapper<ResultSet>() { public ResultSet mapRow(ResultSet rs, int rowNum) throws SQLException { assertEquals(1L, rs.getLong("event")); assertEquals(1L, rs.getLong("id")); assertEquals("What's new in Spring", rs.getString("title")); assertEquals("Come find out what's new in Spring", rs.getString("description")); assertEquals("#newspring", rs.getString("hashtag")); assertEquals(1, rs.getLong("venue")); assertEquals(1, rs.getLong("timeslot")); return null; } }, eventId, eventSessionId); eventLoaderRepository.loadEventSession(new EventSessionData(eventId, eventSessionId, "What's new in Spring?", "Juergen gives the dish on the latest in Spring", "#spring3", 1L, timeSlotId, "NFJS", 24409L, leaderIds)); jdbcTemplate.queryForObject( "select event, id, title, description, hashtag, venue, timeslot from EventSession where event=? and id=?", new RowMapper<ResultSet>() { public ResultSet mapRow(ResultSet rs, int rowNum) throws SQLException { assertEquals(1L, rs.getLong("event")); assertEquals(1L, rs.getLong("id")); assertEquals("What's new in Spring?", rs.getString("title")); assertEquals("Juergen gives the dish on the latest in Spring", rs.getString("description")); assertEquals("#spring3", rs.getString("hashtag")); assertEquals(1, rs.getLong("venue")); assertEquals(1, rs.getLong("timeslot")); return null; } }, eventId, eventSessionId); }
From source file:me.eccentric_nz.plugins.FatPort.FatPortCmdUtils.java
public boolean playerIsAllowed(String name) { boolean bool = false; if (portCommand.containsKey(name)) { int cid = portCommand.get(name); try {//from w w w . ja v a 2s .c o m Connection connection = service.getConnection(); Statement statement = connection.createStatement(); String queryCmd = "SELECT num_uses, cooldown FROM commands WHERE c_id = " + cid; ResultSet rsCmd = statement.executeQuery(queryCmd); if (rsCmd.next()) { int cmd_num = (rsCmd.getInt("num_uses") < 0) ? Integer.MAX_VALUE : rsCmd.getInt("num_uses"); long cooldown = (rsCmd.getLong("cooldown") > 0) ? rsCmd.getLong("cooldown") : 0L; String queryPlayer = "SELECT uses, last_use FROM command_uses WHERE c_id = " + cid + " AND player = '" + name + "'"; ResultSet rsPlayer = statement.executeQuery(queryPlayer); int uses = 0; long now = System.currentTimeMillis(); long last = 0; if (rsPlayer.next()) { uses = rsPlayer.getInt("uses"); last = rsPlayer.getLong("last_use") + (cooldown * 1000L); } if (uses < cmd_num && last < now) { bool = true; } } rsCmd.close(); statement.close(); } catch (SQLException e) { plugin.debug("Could not check for command! " + e); } } return bool; }
From source file:com.silverpeas.gallery.dao.MediaDAO.java
/** * Adding all data of sounds.// ww w.j a v a 2 s. c o m * @param con * @param media * @param sounds * @throws SQLException */ private static void decorateSounds(final Connection con, List<Media> media, Map<String, Sound> sounds) throws SQLException { if (!sounds.isEmpty()) { Collection<Collection<String>> idGroups = CollectionUtil.split(new ArrayList<String>(sounds.keySet())); StringBuilder queryBase = new StringBuilder(SELECT_INTERNAL_MEDIA_PREFIX) .append("S.bitrate, S.duration from SC_Gallery_Internal I join SC_Gallery_Sound S on I.mediaId " + "= S.mediaId where I.mediaId in "); for (Collection<String> mediaIds : idGroups) { PreparedStatement prepStmt = null; ResultSet rs = null; try { prepStmt = con.prepareStatement(DBUtil.appendListOfParameters(queryBase, mediaIds).toString()); DBUtil.setParameters(prepStmt, mediaIds); rs = prepStmt.executeQuery(); while (rs.next()) { String mediaId = rs.getString(1); mediaIds.remove(mediaId); Sound currentSound = sounds.get(mediaId); decorateInternalMedia(rs, currentSound); currentSound.setBitrate(rs.getLong(8)); currentSound.setDuration(rs.getLong(9)); } } finally { DBUtil.close(rs, prepStmt); } // Not found for (String mediaIdNotFound : mediaIds) { Sound currentSound = sounds.remove(mediaIdNotFound); media.remove(currentSound); SilverTrace.warn(GalleryComponentSettings.COMPONENT_NAME, "MediaDAO.decorateSounds()", "root.MSG_GEN_PARAM_VALUE", "sound not found (removed from result): " + mediaIdNotFound); } } } }
From source file:trendgraph.XYLineChart_AWT.java
private XYDataset createDataset() throws SQLException { Database database = new Database(); database.connect();/*from w w w. java 2 s. c o m*/ final XYSeriesCollection dataset = new XYSeriesCollection(); //need year ranges, credit unions, and column to graph //cycle through all of this for each credit union name //replace "MYCOM" with the variable holding the credit union name for (int j = 0; j < creditUnionName.length; j++) { final XYSeries cuName = new XYSeries(creditUnionName[j]); for (int i = yearStart; i <= yearEnd; i++) { int x = 1; creditUnionName[j] = creditUnionName[j].replace("'", "''"); for (double y = i + .25; y <= i + 1; y += .25) { ResultSet rs = database.executeQuery("SELECT [" + columnName + "] FROM Q" + x + "_" + i + " WHERE [Credit Union Name]='" + creditUnionName[j] + "'"); while (rs.next()) { cuName.add(y, rs.getLong(columnName)); } x += 1; } } try { dataset.addSeries(cuName); } catch (IllegalArgumentException ex) { System.out.println("error: selected duplicate credit unions"); } } database.closeconnections(); return dataset; }
From source file:com.flexive.core.storage.MySQL.MySQLSequencerStorage.java
/** * {@inheritDoc}// w w w .ja v a2 s . c o m */ @Override public long getCurrentId(FxSystemSequencer sequencer) throws FxApplicationException { Connection con = null; PreparedStatement ps = null; try { con = Database.getDbConnection(); ps = con.prepareStatement(SQL_GET_CURRVALUE); ps.setString(1, sequencer.getSequencerName()); ResultSet rs = ps.executeQuery(); if (rs != null && rs.next()) return rs.getLong(1); } catch (SQLException exc) { throw new FxDbException(LOG, exc, "ex.db.sqlError", exc.getMessage()); } finally { Database.closeObjects(MySQLSequencerStorage.class, con, ps); } throw new FxCreateException(LOG, "ex.sequencer.notFound", sequencer.getSequencerName()); }
From source file:com.pactera.edg.am.metamanager.extractor.dao.helper.MetadataMapper.java
public Object mapRow(ResultSet rs, int rowNum) throws SQLException { MMMetadata metadata = new MMMetadata(); metadata.setClassifierId(metaModel.getCode()); metadata.setId(rs.getString(1));//from w w w .j a va 2s .c o m metadata.setHasExist(true); metadata.setCode(rs.getString(2)); metadata.setName(rs.getString(3)); metadata.setStartTime(rs.getLong(4)); Map<String, String> mAttributes = metaModel.getMAttrs(); for (Iterator<String> iter = mAttributes.keySet().iterator(); iter.hasNext();) { // ?? String key = iter.next(); // ?varchar String value = rs.getString(mAttributes.get(key)); if (value != null) { metadata.addAttr(key, value); } } // if (parentMetadatasMap != null && parentMetadatasMap.size() > 0) { metadata.setParentMetadata(parentMetadatasMap.get(rs.getString(5))); } return metadata; }
From source file:com.senior.g40.service.UserService.java
public Profile login(String username, String password, char userType) { try {//from ww w . j a v a 2 s. co m Connection conn = ConnectionBuilder.getConnection(); String sqlCmd = "SELECT * FROM drivesafe.user WHERE username = ? AND password = ? AND userType = ?;"; PreparedStatement pstm = conn.prepareStatement(sqlCmd); pstm.setString(1, username); pstm.setString(2, Encrypt.toMD5(password)); pstm.setString(3, String.valueOf(userType)); ResultSet rs = pstm.executeQuery(); if (rs.next()) {//If there is account existed. //TODO System.out.println("LOGIN!"); Profile pf = getProfileByUserId(rs.getLong("userId")); conn.close(); return pf; } } catch (SQLException ex) { Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:eionet.cr.dao.readers.HarvestSourceDTOReader.java
@Override public void readRow(ResultSet rs) throws SQLException, ResultSetReaderException { HarvestSourceDTO harvestSourceDTO = new HarvestSourceDTO(); harvestSourceDTO.setSourceId(new Integer(rs.getInt("HARVEST_SOURCE_ID"))); harvestSourceDTO.setUrl(rs.getString("URL")); harvestSourceDTO.setUrlHash(Long.valueOf(rs.getLong("URL_HASH"))); harvestSourceDTO.setEmails(rs.getString("EMAILS")); harvestSourceDTO.setTimeCreated(rs.getTimestamp("TIME_CREATED")); harvestSourceDTO.setStatements(new Integer(rs.getInt("STATEMENTS"))); harvestSourceDTO.setCountUnavail(new Integer(rs.getInt("COUNT_UNAVAIL"))); harvestSourceDTO.setLastHarvest(rs.getTimestamp("LAST_HARVEST")); harvestSourceDTO.setIntervalMinutes(rs.getInt("INTERVAL_MINUTES")); harvestSourceDTO.setOwner(rs.getString("SOURCE_OWNER")); harvestSourceDTO.setMediaType(rs.getString("MEDIA_TYPE")); String isPrioritySourceStr = rs.getString("PRIORITY_SOURCE"); if (StringUtils.isNotBlank(isPrioritySourceStr)) { harvestSourceDTO.setPrioritySource(YesNoBoolean.parse(isPrioritySourceStr)); }//from www . j a v a 2s . c o m String lastHarvestFailedStr = rs.getString("LAST_HARVEST_FAILED"); if (StringUtils.isNotBlank(lastHarvestFailedStr)) { harvestSourceDTO.setLastHarvestFailed(YesNoBoolean.parse(lastHarvestFailedStr)); } String isPermErrorStr = rs.getString("PERMANENT_ERROR"); if (StringUtils.isNotBlank(isPermErrorStr)) { harvestSourceDTO.setPermanentError(YesNoBoolean.parse(isPermErrorStr)); } String isSparqlEndpointStr = rs.getString("IS_SPARQL_ENDPOINT"); if (StringUtils.isNotBlank(isSparqlEndpointStr)) { harvestSourceDTO.setSparqlEndpoint(YesNoBoolean.parse(isSparqlEndpointStr)); } resultList.add(harvestSourceDTO); }
From source file:com.glaf.core.execution.FileExecutionHelper.java
public long lastModified(Connection connection, String serviceKey, File file) { String sql = " select LASTMODIFIED_ from " + BlobItemDomainFactory.TABLENAME + " where SERVICEKEY_ = ? and FILENAME_ = ? order by LASTMODIFIED_ desc "; PreparedStatement psmt = null; ResultSet rs = null; try {/*from ww w . ja va 2 s . c o m*/ psmt = connection.prepareStatement(sql); psmt.setString(1, serviceKey); psmt.setString(2, file.getAbsolutePath()); rs = psmt.executeQuery(); if (rs.next()) { return rs.getLong(1); } } catch (Exception ex) { logger.error(ex); ex.printStackTrace(); throw new RuntimeException(ex); } finally { JdbcUtils.close(psmt); JdbcUtils.close(rs); } return -1L; }