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:co.nubetech.apache.hadoop.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 ww w . j a va2s . 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; } }
From source file:Model.DAO.java
public void sendEmail(int id, String status) { SimpleDateFormat formatDateTime = new SimpleDateFormat("dd/MM/yyyy-HH:mm"); Properties props = new Properties(); /** Parmetros de conexo com servidor Gmail */ props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.socketFactory.port", "465"); props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.port", "465"); Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("seuemail@gmail.com", "suasenha"); }/*w w w .j a v a 2 s.c o m*/ }); /** Ativa Debug para sesso */ try { PreparedStatement stmt = this.conn .prepareStatement("SELECT * FROM Reservation re WHERE idReservas = ?"); stmt.setInt(1, id); ResultSet rs = stmt.executeQuery(); rs.next(); String date = formatDateTime.format(rs.getTimestamp("dateTime")).split("-")[0]; String time = formatDateTime.format(rs.getTimestamp("dateTime")).split("-")[1]; Message message = new MimeMessage(session); message.setFrom(new InternetAddress("pck1993@gmail.com")); //Remetente Address[] toUser = InternetAddress //Destinatrio(s) .parse(rs.getString("email")); message.setRecipients(Message.RecipientType.TO, toUser); message.setSubject("Status Reserva");//Assunto message.setText("Email de alterao do status da resreva no dia " + date + " s " + time + " horas para " + status); /**Mtodo para enviar a mensagem criada*/ Transport.send(message); } catch (MessagingException e) { throw new RuntimeException(e); } catch (SQLException ex) { Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:dk.nsi.haiba.lprimporter.dao.impl.LPRContactRowMapper.java
@Override public Administration mapRow(ResultSet rs, int rowNum) throws SQLException { Administration adm = new Administration(); adm.setRecordNumber(rs.getString("v_recnum")); adm.setSygehusCode(rs.getString("c_sgh")); adm.setAfdelingsCode(rs.getString("c_afd")); adm.setCpr(rs.getString("v_cpr")); adm.setPatientType(rs.getInt("c_pattype")); Timestamp tsIn = rs.getTimestamp("d_inddto"); // Rule #4 - no minutes and seconds are used in LPR if (tsIn != null) { tsIn.setMinutes(0);/*from w w w . j a v a 2s . c om*/ tsIn.setSeconds(0); adm.setIndlaeggelsesDatetime(new Date(tsIn.getTime())); } Timestamp tsOut = rs.getTimestamp("d_uddto"); if (tsOut != null) { tsOut.setMinutes(0); tsOut.setSeconds(0); adm.setUdskrivningsDatetime(new Date(tsOut.getTime())); } String type = rs.getString("v_type"); if (type != null) { if (DIAGNOSIS.equalsIgnoreCase(type)) { LPRDiagnose d = new LPRDiagnose(); d.setRecordNumber(rs.getString("v_recnum")); d.setDiagnoseCode(rs.getString("c_kode")); d.setTillaegsDiagnose(rs.getString("c_tilkode")); d.setDiagnoseType(rs.getString("c_kodeart")); adm.addLprDiagnose(d); } else { // everything not a diagnosis is a procedure. LPRProcedure p = new LPRProcedure(); p.setRecordNumber(rs.getString("v_recnum")); p.setProcedureCode(rs.getString("c_kode")); p.setTillaegsProcedureCode(rs.getString("c_tilkode")); p.setProcedureType(rs.getString("c_kodeart")); p.setSygehusCode(rs.getString("c_psgh")); p.setAfdelingsCode(rs.getString("c_pafd")); Timestamp ts = rs.getTimestamp("d_pdto"); if (ts != null) { ts.setMinutes(0); ts.setSeconds(0); p.setProcedureDatetime(new Date(ts.getTime())); } adm.addLprProcedure(p); } } return adm; }
From source file:com.hs.mail.imap.dao.MySqlMailboxDao.java
public List<PhysMessage> getDanglingMessageIDList(long ownerID) { String sql = "SELECT m.physmessageid, p.internaldate FROM mailbox b, message m, physmessage p WHERE b.ownerid = ? AND m.physmessageid = p.id AND m.mailboxid = b.mailboxid GROUP BY m.physmessageid HAVING COUNT(m.physmessageid) = 1"; return (List<PhysMessage>) getJdbcTemplate().query(sql, new Object[] { new Long(ownerID) }, new RowMapper() { public Object mapRow(ResultSet rs, int rowNum) throws SQLException { PhysMessage pm = new PhysMessage(); pm.setPhysMessageID(rs.getLong("physmessageid")); pm.setInternalDate(new Date(rs.getTimestamp("internaldate").getTime())); return pm; }/*w w w. j ava2 s . co m*/ }); }
From source file:com.hs.mail.imap.dao.MySqlMailboxDao.java
public List<PhysMessage> getDanglingMessageIDList(long ownerID, long mailboxID) { String sql = "SELECT m.physmessageid, p.internaldate FROM message m, message n, physmessage p WHERE m.mailboxid = ? AND m.physmessageid = n.physmessageid AND m.physmessageid = p.id GROUP BY n.physmessageid HAVING COUNT(n.physmessageid) = 1"; return (List<PhysMessage>) getJdbcTemplate().query(sql, new Object[] { new Long(mailboxID) }, new RowMapper() { public Object mapRow(ResultSet rs, int rowNum) throws SQLException { PhysMessage pm = new PhysMessage(); pm.setPhysMessageID(rs.getLong("physmessageid")); pm.setInternalDate(new Date(rs.getTimestamp("internaldate").getTime())); return pm; }/*w ww. j a v a 2 s . c om*/ }); }
From source file:eu.databata.engine.dao.PropagationSqlLogRowMapper.java
@Override public PropagationSqlLog mapRow(ResultSet rs, int rowNum) throws SQLException { PropagationSqlLog history = new PropagationSqlLog(); history.setModuleName(rs.getString("module_name")); history.setDbChangeCode(rs.getString("db_change_code")); history.setSqlText(rs.getString("sql_text")); history.setRowsUpdated(rs.getLong("rows_updated")); history.setErrorCode(rs.getInt("error_code")); history.setErrorText(rs.getString("error_text")); history.setUpdateTime(rs.getTimestamp("update_time")); history.setExecutionTime(rs.getBigDecimal("execution_time")); return history; }
From source file:com.hs.mail.imap.dao.MySqlMessageDao.java
public PhysMessage getDanglingMessageID(long messageID) { String sql = "SELECT m.physmessageid, p.internaldate FROM message m, physmessage p WHERE m.physmessageid = (SELECT physmessageid FROM message WHERE messageid = ?) AND p.id=m.physmessageid GROUP BY m.physmessageid HAVING COUNT(m.physmessageid) = 1"; return (PhysMessage) queryForObject(sql, new Object[] { new Long(messageID) }, new RowMapper() { public Object mapRow(ResultSet rs, int rowNum) throws SQLException { PhysMessage pm = new PhysMessage(); pm.setPhysMessageID(rs.getLong("physmessageid")); pm.setInternalDate(new Date(rs.getTimestamp("internaldate").getTime())); return pm; }//ww w .j av a 2 s .c om }); }
From source file:net.solarnetwork.node.dao.jdbc.power.JdbcPowerDatumDao.java
@Override @Transactional(readOnly = true, propagation = Propagation.REQUIRED) public List<PowerDatum> getDatumNotUploaded(String destination) { return findDatumNotUploaded(new RowMapper<PowerDatum>() { @Override//from w w w .j av a 2s . co m public PowerDatum mapRow(ResultSet rs, int rowNum) throws SQLException { if (log.isTraceEnabled()) { log.trace("Handling result row " + rowNum); } PowerDatum datum = new PowerDatum(); int col = 1; datum.setCreated(rs.getTimestamp(col++)); datum.setSourceId(rs.getString(col++)); Number val = (Number) rs.getObject(col++); datum.setLocationId(val == null ? null : val.longValue()); val = (Number) rs.getObject(col++); datum.setWatts(val == null ? null : val.intValue()); val = (Number) rs.getObject(col++); datum.setBatteryVolts(val == null ? null : val.floatValue()); val = (Number) rs.getObject(col++); datum.setBatteryAmpHours(val == null ? null : val.doubleValue()); val = (Number) rs.getObject(col++); datum.setDcOutputVolts(val == null ? null : val.floatValue()); val = (Number) rs.getObject(col++); datum.setDcOutputAmps(val == null ? null : val.floatValue()); val = (Number) rs.getObject(col++); datum.setAcOutputVolts(val == null ? null : val.floatValue()); val = (Number) rs.getObject(col++); datum.setAcOutputAmps(val == null ? null : val.floatValue()); val = (Number) rs.getObject(col++); datum.setWattHourReading(val == null ? null : val.longValue()); val = (Number) rs.getObject(col++); datum.setAmpHourReading(val == null ? null : val.doubleValue()); return datum; } }); }
From source file:data.DefaultExchanger.java
protected void putTimestamp(JsonGenerator generator, String fieldName, ResultSet rs, short index) throws SQLException, IOException { generator.writeFieldName(fieldName); Timestamp timestamp = rs.getTimestamp(index); if (timestamp == null) { generator.writeNull();//from w w w . j ava2 s .com } else { generator.writeNumber(timestamp.getTime()); } }
From source file:org.mayocat.shop.billing.store.jdbi.mapper.AbstractOrderMapper.java
protected void fillOrderSummary(ResultSet resultSet, OrderSummary order) throws SQLException { order.setId((UUID) resultSet.getObject("id")); order.setSlug(resultSet.getString("slug")); order.setBillingAddressId((UUID) resultSet.getObject("billing_address_id")); order.setDeliveryAddressId((UUID) resultSet.getObject("delivery_address_id")); order.setCustomerId((UUID) resultSet.getObject("customer_id")); order.setCreationDate(resultSet.getTimestamp("creation_date")); order.setUpdateDate(resultSet.getTimestamp("update_date")); order.setNumberOfItems(resultSet.getLong("number_of_items")); order.setCurrency(Currency.getInstance(resultSet.getString("currency"))); order.setItemsTotal(resultSet.getBigDecimal("items_total")); order.setItemsTotalExcl(resultSet.getBigDecimal("items_total_excl")); order.setShipping(resultSet.getBigDecimal("shipping")); order.setShippingExcl(resultSet.getBigDecimal("shipping_excl")); order.setGrandTotal(resultSet.getBigDecimal("grand_total")); order.setGrandTotalExcl(resultSet.getBigDecimal("grand_total_excl")); order.setStatus(OrderSummary.Status.valueOf(resultSet.getString("status"))); order.setAdditionalInformation(resultSet.getString("additional_information")); ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new GuavaModule()); try {/*ww w . j a va2 s . c om*/ Map<String, Object> data = mapper.readValue(resultSet.getString("order_data"), new TypeReference<Map<String, Object>>() { }); order.setOrderData(data); } catch (IOException e) { logger.error("Failed to deserialize order data", e); } }