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.px100systems.data.plugin.persistence.jdbc.Storage.java
protected Map<String, Long> loadMaxIds() { final Map<String, Long> result = new HashMap<String, Long>(); connection.getJdbc().query("SELECT MAX(id), generator_name FROM " + table + " GROUP BY generator_name", new RowCallbackHandler() { @Override/*from ww w.ja v a 2 s .com*/ public void processRow(ResultSet rs) throws SQLException { result.put(rs.getString("generator_name"), rs.getLong(1)); } }); return result; }
From source file:br.gov.jfrj.siga.gc.gsa.GcInformacaoAdaptor.java
protected void pushDocIds(DocIdPusher pusher, Date date) throws InterruptedException { Connection conn = null;// w w w . j a va 2s .c om Statement stmt = null; String query = "select id_informacao from sigagc.gc_informacao where numero is not null and his_dt_fim is null"; try { BufferingPusher outstream = new BufferingPusher(pusher); conn = getConnection(); stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(query); while (rs.next()) { DocId id = new DocId("" + rs.getLong("ID_INFORMACAO")); outstream.add(id); } outstream.forcePush(); } catch (Exception ex) { throw new RuntimeException(ex); } finally { if (stmt != null) { try { stmt.close(); } catch (SQLException e) { e.printStackTrace(); } } if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } }
From source file:henu.dao.impl.CaclDaoImpl.java
@Override public long[] getCaclUserList(String cid) { String sql = "select uid from uc where cid = " + cid; System.out.println(sql);//from w w w . j a v a2 s. co m ResultSet rs = SqlDB.executeQuery(sql); List<Long> arraylist = new ArrayList(); try { while (rs.next()) { arraylist.add(rs.getLong("uid")); System.out.println("UID: " + rs.getInt("uid")); } } catch (SQLException ex) { } long[] list = ArrayUtils.toPrimitive(arraylist.toArray(new Long[arraylist.size()])); SqlDB.close(); return list; }
From source file:com.anyuan.thomweboss.persistence.jdbcimpl.user.UserDaoJdbcImpl.java
/** * TODO// w w w. j a v a2 s . c o m * @author Thomsen * @since Jul 14, 2013 10:34:57 PM * @param id * @param preState * @return * @throws SQLException */ private long generateId(PreparedStatement preState) throws SQLException { long id = -1; ResultSet rs = preState.getGeneratedKeys(); if (null != rs && rs.next()) { id = rs.getLong(1); } return id; }
From source file:net.solarnetwork.node.dao.jdbc.test.PreparedStatementCsvReaderTests.java
@Test public void importTable() throws Exception { final String tableName = "SOLARNODE.TEST_CSV_IO"; executeSqlScript("net/solarnetwork/node/dao/jdbc/test/csv-data-01.sql", false); importData(tableName);/*from ww w .j a va 2 s .c o m*/ final MutableInt row = new MutableInt(0); final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); final Calendar utcCalendar = Calendar.getInstance(TimeZone.getTimeZone("UTC")); jdbcTemplate.query(new PreparedStatementCreator() { @Override public PreparedStatement createPreparedStatement(Connection con) throws SQLException { // TODO Auto-generated method stub return con.prepareStatement("select PK,STR,INUM,DNUM,TS from solarnode.test_csv_io order by pk"); } }, new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { row.increment(); final int i = row.intValue(); assertEquals("PK " + i, i, rs.getLong(1)); if (i == 2) { assertNull("STR " + i, rs.getString(2)); } else { assertEquals("STR " + i, "s0" + i, rs.getString(2)); } if (i == 3) { assertNull("INUM " + i, rs.getObject(3)); } else { assertEquals("INUM " + i, i, rs.getInt(3)); } if (i == 4) { assertNull("DNUM " + i, rs.getObject(4)); } else { assertEquals("DNUM " + i, i, rs.getDouble(4), 0.01); } if (i == 5) { assertNull("TS " + i, rs.getObject(5)); } else { Timestamp ts = rs.getTimestamp(5, utcCalendar); try { assertEquals("TS " + i, sdf.parse("2016-10-0" + i + "T12:01:02.345Z"), ts); } catch (ParseException e) { // should not get here } } } }); assertEquals("Imported count", 5, row.intValue()); }
From source file:com.springsource.greenhouse.events.load.JdbcEventLoaderRepositoryTest.java
@Test public void loadTimeSlot() 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-15T01:30:00", "NFJS", 6296)); assertEquals(1L, timeSlotId);//from ww w. ja v a2 s .c om jdbcTemplate.queryForObject("select id, event, label, startTime, endTime from EventTimeSlot where id=?", new RowMapper<ResultSet>() { public ResultSet mapRow(ResultSet rs, int rowNum) throws SQLException { assertEquals(1L, rs.getLong("id")); assertEquals(1L, rs.getLong("event")); assertEquals("Time Slot 1", rs.getString("label")); Timestamp startTime = rs.getTimestamp("startTime"); Timestamp endTime = rs.getTimestamp("endTime"); // assertEquals(new DateTime(2012, 10, 15, 0, 0, 0, 0, DateTimeZone.getDefault()).getMillis(), startTime.getTime()); // assertEquals(new DateTime(2012, 10, 15, 1, 30, 0, 0, DateTimeZone.getDefault()).getMillis(), endTime.getTime()); return null; } }, timeSlotId); }
From source file:com.sander.verhagen.domain.Message.java
/** * Constructor.//from w w w .ja v a2 s .c o m * * @param resultSet * record as pulled from the Skype database * @throws SQLException * problem with database access */ public Message(ResultSet resultSet) throws SQLException { this.chatName = resultSet.getString("chatname"); this.body = resultSet.getString("body_xml"); this.author = resultSet.getString("author"); this.authorDisplay = resultSet.getString("from_dispname"); this.time = resultSet.getLong("timestamp"); }
From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccXMsgClient.CFAccXMsgClientSchema.java
public static Long getNullableUInt32(ResultSet reader, int colidx) { try {/* w w w .ja v a 2 s . co m*/ long val = reader.getLong(colidx); if (reader.wasNull()) { return (null); } else { return (new Long(val)); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(CFAccXMsgClientSchema.class, "getNullableUInt32", e); } }
From source file:com.springsource.greenhouse.events.load.JdbcEventLoaderRepositoryTest.java
@Test public void loadLeaderData() throws SQLException { long leaderId = eventLoaderRepository.loadLeader(new LeaderData("Craig Walls", "Craig is the Spring Social project lead", "http://www.habuma.com", "habuma", "NFJS", 1234)); assertEquals(1L, leaderId);//w w w. j a v a 2 s . c o m jdbcTemplate.queryForObject("select id, name, bio, personalUrl, twitterUsername from Leader where id=?", new RowMapper<ResultSet>() { public ResultSet mapRow(ResultSet rs, int rowNum) throws SQLException { assertEquals(1L, rs.getLong("id")); assertEquals("Craig Walls", rs.getString("name")); assertEquals("Craig is the Spring Social project lead", rs.getString("bio")); assertEquals("http://www.habuma.com", rs.getString("personalUrl")); assertEquals("habuma", rs.getString("twitterUsername")); return null; } }, leaderId); jdbcTemplate.queryForObject("select leader, sourceId, source from ExternalLeader where leader=?", new RowMapper<ResultSet>() { public ResultSet mapRow(ResultSet rs, int rowNum) throws SQLException { assertEquals(1L, rs.getLong("leader")); assertEquals(1234L, rs.getLong("sourceId")); assertEquals("NFJS", rs.getString("source")); return null; } }, leaderId); }
From source file:nl.ordina.bag.etl.dao.AbstractBAGMutatiesDAO.java
@Override public MutatiesFile getNexMutatiesFile() throws DAOException { try {//from w ww . j av a 2s.c o m MutatiesFile file = jdbcTemplate.queryForObject( "select *" + " from bag_mutaties_file" + " where date_from = (select (max(date_to)) from bag_mutaties_file where status = " + ProcessingStatus.PROCESSED.ordinal() + ")", // + //" union all" + //" select *" + //" from bag_mutaties_file" + //" where date_from = (select (min(date_from)) from bag_mutaties_file where status = " + ProcessingStatus.UNPROCESSED.ordinal() + //" and (select count(id) from bag_mutaties_file where status = " + ProcessingStatus.PROCESSED.ordinal() + ") = 0)", new RowMapper<MutatiesFile>() { @Override public MutatiesFile mapRow(ResultSet rs, int row) throws SQLException { MutatiesFile object = new MutatiesFile(); object.setId(rs.getLong("id")); object.setDateFrom(rs.getDate("date_from")); object.setDateTo(rs.getDate("date_to")); object.setContent(rs.getBytes("content")); object.setStatus(ProcessingStatus.values()[rs.getInt("status")]); return object; } }); return file; } catch (IncorrectResultSizeDataAccessException e) { return null; } catch (DataAccessException e) { throw new DAOException(e); } }