List of usage examples for java.sql ResultSet getInt
int getInt(String columnLabel) throws SQLException;
ResultSet
object as an int
in the Java programming language. From source file:no.magott.training.ex2.ExchangeRateRowMapper.java
@Override public ExchangeRate mapRow(ResultSet rs, int rowNum) throws SQLException { ExchangeRate exchangeRate = new ExchangeRate(); exchangeRate.setId(rs.getInt("ID")); exchangeRate.setExchangeRate(rs.getDouble("EXCHANGE_RATE")); exchangeRate.setDate(rs.getDate("EXCHANGE_DATE")); exchangeRate.setFrom(rs.getString("FROM_CURRENCY")); exchangeRate.setTo(rs.getString("TO_CURRENCY")); return exchangeRate; }
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/* w w w. j a v a 2 s . c o m*/ 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:com.havoc.hotel.admin.dao.impl.CheckinDAOImpl.java
private Checkin mapData(ResultSet rs) throws SQLException { Checkin c = new Checkin(); c.setCheckinId(rs.getInt("checkin_id")); Booking b = new Booking(); b.setBookingId(rs.getInt("booking_id")); b.setFirstName(rs.getString("first_name")); b.setLastName(rs.getString("last_name")); Room r = new Room(); r.setRoomPrice(rs.getInt("room_price")); r.setRoomNumber(rs.getInt("room_number")); b.setRoom(r);// w w w . j a v a 2s .c om b.setCheckinDate(rs.getDate("checkin_date")); b.setTotalDays(rs.getInt("total_days")); b.setTotalNights(rs.getInt("total_nights")); b.setTotalPrice(rs.getInt("total_price")); b.setCheckoutDate(rs.getDate("checkout_date")); c.setBooking(b); return c; }
From source file:edu.ku.brc.specify.conversion.ConvertMiscData.java
/** * @param oldDBConn//from ww w . j a v a2 s. c om * @param newDBConn * @param disciplineID */ public static void convertMethodFromStratGTP(final Connection oldDBConn, final Connection newDBConn) { String sql = null; Session localSession = null; try { localSession = HibernateUtil.getCurrentSession(); HibernateUtil.beginTransaction(); // Query to Create PickList sql = "SELECT gtp.Name, CONCAT(gtp.Name,' - ', gtp.Standard) as Method FROM collectingevent AS ce " + "Inner Join stratigraphy AS s ON ce.CollectingEventID = s.StratigraphyID " + "Inner Join geologictimeperiod AS gtp ON s.GeologicTimePeriodID = gtp.GeologicTimePeriodID " + "GROUP BY gtp.Name"; PickList pl = (PickList) localSession.createQuery("FROM PickList WHERE Name = 'CollectingMethod'") .list().get(0); if (pl == null) { log.error("Couldn't find CollectingMethod."); } for (PickListItem pli : new Vector<PickListItem>(pl.getPickListItems())) { log.debug("Removing[" + pli.getTitle() + "]"); localSession.delete(pli); pl.getPickListItems().remove(pli); } localSession.saveOrUpdate(pl); HibernateUtil.commitTransaction(); HibernateUtil.beginTransaction(); Vector<Object[]> list = BasicSQLUtils.query(oldDBConn, sql); for (Object[] cols : list) { PickListItem pli = new PickListItem(); pli.initialize(); pli.setTitle(cols[1].toString()); pli.setValue(cols[0].toString()); pl.getPickListItems().add(pli); pli.setPickList(pl); localSession.saveOrUpdate(pli); } localSession.saveOrUpdate(pl); HibernateUtil.commitTransaction(); // Query for processing data sql = "SELECT ce.CollectingEventID, gtp.Name FROM collectingevent AS ce " + "Inner Join stratigraphy AS s ON ce.CollectingEventID = s.StratigraphyID " + "Inner Join geologictimeperiod AS gtp ON s.GeologicTimePeriodID = gtp.GeologicTimePeriodID " + "ORDER BY ce.CollectingEventID ASC"; IdMapperMgr.getInstance().setDBs(oldDBConn, newDBConn); IdMapperIFace mapper = IdMapperMgr.getInstance().addTableMapper("collectingevent", "CollectingEventID", false); PreparedStatement pStmt = newDBConn .prepareStatement("UPDATE collectingevent SET Method=? WHERE CollectingEventID=?"); Statement stmt = oldDBConn.createStatement(); ResultSet rs = stmt.executeQuery(sql); while (rs.next()) { Integer newId = mapper.get(rs.getInt(1)); pStmt.setString(1, rs.getString(2)); pStmt.setInt(2, newId); pStmt.executeUpdate(); } rs.close(); stmt.close(); } catch (Exception ex) { ex.printStackTrace(); HibernateUtil.rollbackTransaction(); } }
From source file:com.dai.jdbc.TipoEstatisticaExtractor.java
public TipoEstatistica extractData(ResultSet resultSet) throws SQLException, DataAccessException { TipoEstatistica te = new TipoEstatistica(); te.setIdTipoEstatistica(resultSet.getInt("idTiposEstatistica")); te.setDesignacaoEstatistica(resultSet.getString("designacaoEstatistica")); return te;// w w w. j a va 2 s.c om }
From source file:org.smigo.species.JdbcRuleDao.java
@Override public List<Rule> getRules() { final Map<Integer, List<Integer>> impacts = getImpacts(); return jdbcTemplate.query(SELECT, new RowMapper<Rule>() { @Override// w w w . j a v a2 s . co m public Rule mapRow(ResultSet rs, int rowNum) throws SQLException { final int id = rs.getInt("id"); final int host = rs.getInt("host"); final int type = rs.getInt("type"); final int causerSpecies = rs.getInt("causer"); //todo rename to causerspecies final int causerFamily = rs.getInt("causerfamily"); final int gap = rs.getInt("gap"); //todo should return null if not set return Rule.create(id, host, type, causerSpecies, causerFamily, gap, impacts.get(id)); } }); }
From source file:com.espertech.esper.epl.db.TestDatabaseDMConnFactory.java
private void tryAndCloseConnection(Connection connection) throws Exception { Statement stmt = connection.createStatement(); stmt.execute("select 1 from dual"); ResultSet result = stmt.getResultSet(); result.next();/*w ww . j a v a 2 s .c o m*/ assertEquals(1, result.getInt(1)); result.close(); stmt.close(); connection.close(); }
From source file:DAO.Poll_Tbl_pkg.Poll_Tbl_Mapper.java
@Override public Poll_Tbl mapRow(ResultSet rs, int rowNum) throws SQLException { Poll_Tbl poll_tbl = new Poll_Tbl(); poll_tbl.setPid(rs.getInt("pid")); poll_tbl.setUid(rs.getInt("uid")); // next 2 lines to remove the 1st and the last comma from cid_json String cid_json = rs.getString("cid_json"); String cid_json2 = cid_json.substring(1, cid_json.length() - 1); poll_tbl.setCid_json(cid_json2, conn); //poll_tbl.setCid_json(rs.getString("cid_json"),conn); poll_tbl.setTitle(rs.getString("title")); poll_tbl.setDescription(rs.getString("description")); poll_tbl.setQtn_json(rs.getString("qtn_json")); //poll_tbl.setAns_json(rs.getString("ans_json")); poll_tbl.setPoll_link(rs.getString("poll_link")); poll_tbl.setStart_ts(rs.getString("start_ts")); poll_tbl.setEnd_ts(rs.getString("end_ts")); poll_tbl.setReward(rs.getInt("reward")); poll_tbl.setPoll_type(rs.getString("poll_type")); return poll_tbl; }
From source file:business.management.system.Chart.java
private PieDataset createPieDataset() throws SQLException { DefaultPieDataset dataset = new DefaultPieDataset(); ResultSet rs = Methods.getTeamProjectCount(); while (rs.next()) { int id = rs.getInt("team_id"); int count = rs.getInt(2); dataset.setValue("team id: " + id, new Double(count)); }/*w ww. ja va2s . c o m*/ return dataset; }
From source file:com.dai.jdbc.CompeticaoExtractor.java
public Competicao extractData(ResultSet resultSet) throws SQLException, DataAccessException { Competicao competicao = new Competicao(); competicao.setIdCompeticao(resultSet.getInt("idCompeticao")); competicao.setDesignacao(resultSet.getString("designacaoCompeticao")); competicao.setIdEscalao(resultSet.getInt("escalao_idEscalao_c")); return competicao; }