List of usage examples for java.sql ResultSet getTimestamp
java.sql.Timestamp getTimestamp(String columnLabel) throws SQLException;
ResultSet
object as a java.sql.Timestamp
object in the Java programming language. From source file:net.bhira.sample.api.jdbc.DepartmentRowMapper.java
/** * Constructor for DepartmentRowMapper that creates an instance of * {@link net.bhira.sample.model.Department} from row represented by rowNum in the given * ResultSet.// w ww .ja v a 2 s . co m * * @param rs * an instance of ResultSet to be processed. * @param rowNum * integer representing the row number in ResultSet. */ @Override public Department mapRow(ResultSet rs, int rowNum) throws SQLException { Department department = new Department(); department.setId(rs.getLong("id")); department.setCompanyId(rs.getLong("companyid")); department.setName(rs.getString("name")); department.setBillingAddress(rs.getString("billingaddr")); department.setShippingAddress(rs.getString("shippingaddr")); department.setCreated(rs.getTimestamp("created")); department.setModified(rs.getTimestamp("modified")); department.setCreatedBy(rs.getString("createdby")); department.setModifiedBy(rs.getString("modifiedby")); return department; }
From source file:ru.org.linux.topic.TopTenDao.java
public List<TopTenMessageDTO> getMessages() { String sql = "select topics.id as msgid, groups.urlname, groups.section, topics.title, lastmod, topics.stat1 as c " + "from topics " + "join groups on groups.id = topics.groupid" + " where topics.postdate>(CURRENT_TIMESTAMP-'1 month 1 day'::interval) and not deleted and notop is null " + " and groupid!=8404 and groupid!=4068 order by c desc, msgid limit 10"; return jdbcTemplate.query(sql, new RowMapper<TopTenMessageDTO>() { @Override/*from w w w . j ava2 s . c o m*/ public TopTenMessageDTO mapRow(ResultSet rs, int i) throws SQLException { TopTenMessageDTO result = new TopTenMessageDTO(); result.setUrl(sectionService.getSection(rs.getInt("section")).getSectionLink() + rs.getString("urlname") + '/' + rs.getInt("msgid")); result.setTitle(rs.getString("title")); result.setLastmod(rs.getTimestamp("lastmod")); result.setAnswers(rs.getInt("c")); return result; } }); }
From source file:uk.ac.kcl.rowmappers.DocumentRowMapper.java
private void mapDBMetadata(Document doc, ResultSet rs) throws SQLException { doc.setSrcTableName(rs.getString(srcTableName)); doc.setSrcColumnFieldName(rs.getString(srcColumnFieldName)); doc.setPrimaryKeyFieldName(rs.getString(primaryKeyFieldName)); doc.setPrimaryKeyFieldValue(rs.getString(primaryKeyFieldValue)); doc.setTimeStamp(rs.getTimestamp(timeStamp)); }
From source file:net.solarnetwork.node.dao.jdbc.consumption.test.JdbcConsumptionDatumDaoTest.java
@Test public void storeNew() { ConsumptionDatum datum = new ConsumptionDatum(TEST_SOURCE_ID, TEST_AMPS, TEST_VOLTS); datum.setCreated(new Date()); datum.setWattHourReading(TEST_WATT_HOUR_READING); dao.storeDatum(datum);/*from ww w.j a v a 2 s . com*/ jdbcOps.query(SQL_GET_BY_ID, new Object[] { new java.sql.Timestamp(datum.getCreated().getTime()), TEST_SOURCE_ID }, new ResultSetExtractor<Object>() { @Override public Object extractData(ResultSet rs) throws SQLException, DataAccessException { assertTrue("Must have one result", rs.next()); int col = 1; String s = rs.getString(col++); assertFalse(rs.wasNull()); assertEquals(TEST_SOURCE_ID, s); rs.getTimestamp(col++); assertFalse(rs.wasNull()); Float f = rs.getFloat(col++); assertFalse(rs.wasNull()); assertEquals(TEST_VOLTS.doubleValue(), f.doubleValue(), 0.001); f = rs.getFloat(col++); assertFalse(rs.wasNull()); assertEquals(TEST_AMPS.doubleValue(), f.doubleValue(), 0.001); Long l = rs.getLong(col++); assertFalse(rs.wasNull()); assertEquals(TEST_WATT_HOUR_READING, l); assertFalse("Must not have more than one result", rs.next()); return null; } }); }
From source file:net.solarnetwork.node.dao.jdbc.general.JdbcGeneralLocationDatumDao.java
@Override @Transactional(readOnly = true, propagation = Propagation.REQUIRED) public List<GeneralLocationDatum> getDatumNotUploaded(String destination) { return findDatumNotUploaded(new RowMapper<GeneralLocationDatum>() { @Override/* www . ja v a 2 s . co m*/ public GeneralLocationDatum mapRow(ResultSet rs, int rowNum) throws SQLException { if (log.isTraceEnabled()) { log.trace("Handling result row " + rowNum); } GeneralLocationDatum datum = new GeneralLocationDatum(); int col = 0; datum.setCreated(rs.getTimestamp(++col)); datum.setLocationId(rs.getLong(++col)); datum.setSourceId(rs.getString(++col)); String jdata = rs.getString(++col); if (jdata != null) { GeneralLocationDatumSamples s; try { s = objectMapper.readValue(jdata, GeneralLocationDatumSamples.class); datum.setSamples(s); } catch (IOException e) { log.error("Error deserializing JSON into GeneralLocationDatumSamples: {}", e.getMessage()); } } return datum; } }); }
From source file:com.ewcms.component.comment.dao.CommentDAO.java
@Override public List<Comment> findCommentPage(final int articleId, final int page, final int row) { String sql = "Select * From component_comment Where article_id = ? Limit ? OffSet ?"; int offset = page * row; Object[] params = { articleId, row, offset }; return jdbcTemplate.query(sql, params, new RowMapper<Comment>() { @Override//from ww w. j a va 2 s .com public Comment mapRow(ResultSet rs, int rowNum) throws SQLException { Comment comment = new Comment(); comment.setId(rs.getLong("id")); comment.setArticleId(rs.getInt("article_id")); comment.setIp(rs.getString("ip")); comment.setUsername(rs.getString("username")); comment.setDate(rs.getTimestamp("date")); comment.setReplies(findReply(comment.getId())); return comment; } }); }
From source file:com.butler.service.OrderDao.java
public List<OrderDetails> getPendingOrders() { String sql = "select name, o.number, address, o.feedback,o.product, o.quantity, o.immediate,o.stamp as time from orders o,(select name,address,number from user)as y where o.number = y.number and o.status='TODO' order by time desc"; //return this.getJdbcTemplate().queryForList(sql, OrderDetails.class); return this.getJdbcTemplate().query(sql, new RowMapper() { public Object mapRow(ResultSet rs, int i) throws SQLException { OrderDetails details = new OrderDetails(); details.setName(rs.getString("name")); details.setNumber(rs.getString("number")); details.setAddress(rs.getString("address")); details.setProduct(rs.getString("product")); details.setQuantity(rs.getString("quantity")); Timestamp time = rs.getTimestamp("time"); details.setTime(Util.getIndianTime(time)); details.setFeedback(rs.getString("feedback")); details.setImmediate(rs.getBoolean("immediate")); return details; }// ww w. j a va2 s. c om }); }
From source file:com.sql.EmailOutInvites.java
/** * Get a list of all of the email invites awaiting to be sent. * /* w ww . ja v a 2 s. c o m*/ * @return List EmailOutInvitesModel */ public static List<EmailOutInvitesModel> getQueuedEmailInvites() { List<EmailOutInvitesModel> list = new ArrayList(); Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; try { conn = DBConnection.connectToDB(); String sql = "SELECT * FROM EmailOutInvites"; ps = conn.prepareStatement(sql); rs = ps.executeQuery(); while (rs.next()) { EmailOutInvitesModel item = new EmailOutInvitesModel(); item.setId(rs.getInt("id")); item.setSection(rs.getString("Section") == null ? "" : rs.getString("Section")); item.setToAddress(rs.getString("TOaddress") == null ? "" : rs.getString("TOaddress")); item.setCcAddress(rs.getString("CCaddress") == null ? "" : rs.getString("CCaddress")); item.setEmailBody(rs.getString("emailBody") == null ? "" : rs.getString("emailBody")); item.setCaseNumber(rs.getString("caseNumber") == null ? "" : rs.getString("caseNumber")); item.setHearingType(rs.getString("hearingType") == null ? "" : rs.getString("hearingType")); item.setHearingRoomAbv( rs.getString("hearingRoomAbv") == null ? "" : rs.getString("hearingRoomAbv")); item.setHearingDescription( rs.getString("hearingDescription") == null ? "" : rs.getString("hearingDescription")); item.setHearingStartTime( CalendarCalculation.adjustTimeZoneOffset(rs.getTimestamp("hearingStartTime"))); item.setHearingEndTime(CalendarCalculation.adjustTimeZoneOffset(rs.getTimestamp("hearingEndTime"))); item.setEmailSubject(rs.getString("emailSubject") == null ? "" : rs.getString("emailSubject")); list.add(item); } } catch (SQLException ex) { ExceptionHandler.Handle(ex); } finally { DbUtils.closeQuietly(conn); DbUtils.closeQuietly(ps); DbUtils.closeQuietly(rs); } return list; }
From source file:Model.DAO.java
public ArrayList<Reservation> listReservations(int idRestaurant) { ArrayList<Reservation> reservationList = new ArrayList<Reservation>(); PreparedStatement stmt;//from w w w.ja v a 2 s.co m SimpleDateFormat formatDateTime = new SimpleDateFormat("dd/MM/yyyy-HH:mm"); try { stmt = this.conn.prepareStatement( "SELECT * FROM Reservation, ReservationStatus WHERE idRestaurant = ? and StatusFK = idReservationStatus;"); stmt.setInt(1, idRestaurant); ResultSet rs = stmt.executeQuery(); while (rs.next()) { String date = formatDateTime.format(rs.getTimestamp("dateTime")); reservationList.add(new Reservation(rs.getInt("idReservas"), rs.getInt("idRestaurant"), rs.getString("name"), rs.getString("email"), date, rs.getString("Status"))); } } catch (SQLException ex) { Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex); } if (reservationList.isEmpty()) { return null; } return reservationList; }
From source file:com.cloudera.sqoop.mapreduce.db.DateSplitter.java
/** Retrieve the value from the column in a type-appropriate manner and return its timestamp since the epoch. If the column is null, then return Long.MIN_VALUE. This will cause a special split to be generated for the NULL case, but may also cause poorly-balanced splits if most of the actual dates are positive time since the epoch, etc. *///from w ww . j a va 2 s .c o m private long resultSetColToLong(ResultSet rs, int colNum, int sqlDataType) throws SQLException { try { switch (sqlDataType) { case Types.DATE: return rs.getDate(colNum).getTime(); case Types.TIME: return rs.getTime(colNum).getTime(); case Types.TIMESTAMP: return rs.getTimestamp(colNum).getTime(); default: throw new SQLException("Not a date-type field"); } } catch (NullPointerException npe) { // null column. return minimum long value. LOG.warn("Encountered a NULL date in the split column. " + "Splits may be poorly balanced."); return Long.MIN_VALUE; } }