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:mysql5.MySQL5PlayerDAO.java
/** * {@inheritDoc}//w ww . j a va2 s . com */ @Override public void setCreationDeletionTime(final PlayerAccountData acData) { DB.select("SELECT creation_date, deletion_date FROM players WHERE id = ?", new ParamReadStH() { @Override public void setParams(PreparedStatement stmt) throws SQLException { stmt.setInt(1, acData.getPlayerCommonData().getPlayerObjId()); } @Override public void handleRead(ResultSet rset) throws SQLException { rset.next(); acData.setDeletionDate(rset.getTimestamp("deletion_date")); acData.setCreationDate(rset.getTimestamp("creation_date")); } }); }
From source file:eionet.meta.dao.mysql.SiteCodeDAOImpl.java
/** * {@inheritDoc}// w w w.ja v a2 s .com */ @Override public SiteCodeResult searchSiteCodes(SiteCodeFilter filter) { Map<String, Object> params = new HashMap<String, Object>(); String sql = getSiteCodesSql(filter, params); List<SiteCode> resultList = getNamedParameterJdbcTemplate().query(sql.toString(), params, new RowMapper<SiteCode>() { @Override public SiteCode mapRow(ResultSet rs, int rowNum) throws SQLException { SiteCode sc = new SiteCode(); sc.setId(rs.getInt("vc.VOCABULARY_CONCEPT_ID")); sc.setIdentifier(rs.getString("vc.IDENTIFIER")); sc.setLabel(rs.getString("vc.LABEL")); sc.setDefinition(rs.getString("vc.DEFINITION")); sc.setNotation(rs.getString("vc.NOTATION")); sc.setSiteCodeStatus(SiteCodeStatus.valueOf(rs.getString("sc.STATUS"))); sc.setCountryCode(rs.getString("sc.CC_ISO2")); sc.setDateCreated(rs.getTimestamp("sc.DATE_CREATED")); sc.setUserCreated(rs.getString("sc.USER_CREATED")); sc.setDateAllocated(rs.getTimestamp("sc.DATE_ALLOCATED")); sc.setUserAllocated(rs.getString("sc.USER_ALLOCATED")); sc.setInitialSiteName(rs.getString("sc.INITIAL_SITE_NAME")); sc.setYearsDeleted(rs.getString("sc.YEARS_DELETED")); sc.setYearsDisappeared(rs.getString("sc.YEARS_DISAPPEARED")); return sc; } }); String totalSql = "SELECT FOUND_ROWS()"; int totalItems = getJdbcTemplate().queryForInt(totalSql); SiteCodeResult result = new SiteCodeResult(resultList, totalItems, filter); return result; }
From source file:com.google.visualization.datasource.util.SqlDataSourceHelper.java
/** * Creates a table cell from the value in the current row of the given result * set and the given column index. The type of the value is determined by the * given value type.// w w w . j av a2 s . c o m * * @param rs The result set holding the data from the sql table. The result * points to the current row. * @param valueType The value type of the column that the cell belongs to. * @param column The column index. Indexes are 0-based. * * @return The table cell. * * @throws SQLException Thrown when the connection to the database failed. */ private static TableCell buildTableCell(ResultSet rs, ValueType valueType, int column) throws SQLException { Value value = null; // SQL indexes are 1- based. column = column + 1; switch (valueType) { case BOOLEAN: value = BooleanValue.getInstance(rs.getBoolean(column)); break; case NUMBER: value = new NumberValue(rs.getDouble(column)); break; case DATE: Date date = rs.getDate(column); // If date is null it is handled later. if (date != null) { GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT")); // Set the year, month and date in the gregorian calendar. // Use the 'set' method with those parameters, and not the 'setTime' // method with the date parameter, since the Date object contains the // current time zone and it's impossible to change it to 'GMT'. gc.set(date.getYear() + 1900, date.getMonth(), date.getDate()); value = new DateValue(gc); } break; case DATETIME: Timestamp timestamp = rs.getTimestamp(column); // If timestamp is null it is handled later. if (timestamp != null) { GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT")); // Set the year, month, date, hours, minutes and seconds in the // gregorian calendar. Use the 'set' method with those parameters, // and not the 'setTime' method with the timestamp parameter, since // the Timestamp object contains the current time zone and it's // impossible to change it to 'GMT'. gc.set(timestamp.getYear() + 1900, timestamp.getMonth(), timestamp.getDate(), timestamp.getHours(), timestamp.getMinutes(), timestamp.getSeconds()); // Set the milliseconds explicitly, as they are not saved in the // underlying date. gc.set(Calendar.MILLISECOND, timestamp.getNanos() / 1000000); value = new DateTimeValue(gc); } break; case TIMEOFDAY: Time time = rs.getTime(column); // If time is null it is handled later. if (time != null) { GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT")); // Set the hours, minutes and seconds of the time in the gregorian // calendar. Set the year, month and date to be January 1 1970 like // in the Time object. // Use the 'set' method with those parameters, // and not the 'setTime' method with the time parameter, since // the Time object contains the current time zone and it's // impossible to change it to 'GMT'. gc.set(1970, Calendar.JANUARY, 1, time.getHours(), time.getMinutes(), time.getSeconds()); // Set the milliseconds explicitly, otherwise the milliseconds from // the time the gc was initialized are used. gc.set(GregorianCalendar.MILLISECOND, 0); value = new TimeOfDayValue(gc); } break; default: String colValue = rs.getString(column); if (colValue == null) { value = TextValue.getNullValue(); } else { value = new TextValue(rs.getString(column)); } break; } // Handle null values. if (rs.wasNull()) { return new TableCell(Value.getNullValueFromValueType(valueType)); } else { return new TableCell(value); } }
From source file:com.sfs.whichdoctor.dao.WhichDoctorDAOImpl.java
/** * Load history./*from ww w . j a v a 2 s. c o m*/ * * @param rs the rs * * @return the which doctor bean * * @throws SQLException the SQL exception */ private WhichDoctorBean loadHistory(final ResultSet rs) throws SQLException { WhichDoctorBean whichdoctor = new WhichDoctorBean(); whichdoctor.setGUID(rs.getInt("GUID")); whichdoctor.setId(rs.getInt("Id")); whichdoctor.setDescription(rs.getString("Description")); try { whichdoctor.setEntryCreatedDate(rs.getTimestamp("Created")); } catch (SQLException sqe) { dataLogger.debug("Error setting Created date: " + sqe.getMessage()); } whichdoctor.setLogMessage(rs.getString("LogMessage")); whichdoctor.setActive(rs.getBoolean("Active")); UserBean user = new UserBean(); user.setDN(rs.getString("CreatedBy")); user.setPreferredName(rs.getString("PreferredName")); user.setLastName(rs.getString("LastName")); whichdoctor.setEntryCreatedUser(user); return whichdoctor; }
From source file:com.ewcms.component.interaction.dao.InteractionDAO.java
private Interaction interactionRowMapper(ResultSet rs) throws SQLException { Interaction vo = new Interaction(); vo.setId(rs.getInt("id")); vo.setUsername(rs.getString("username")); vo.setTitle(rs.getString("title")); vo.setContent(rs.getString("content")); vo.setReplay(rs.getString("replay")); vo.setType(rs.getInt("type")); vo.setState(InteractionState.values()[rs.getInt("state")]); vo.setIp(rs.getString("ip")); vo.setChecked(rs.getBoolean("checked")); vo.setDate(rs.getTimestamp("date")); vo.setReplayDate(rs.getTimestamp("replay_date")); vo.setCounter(rs.getInt("counter")); vo.setName(rs.getString("name")); Organ organ = new Organ(rs.getInt("organ_id"), rs.getString("organ_name")); vo.setOrgan(organ);//from ww w.j ava2 s . c om return vo; }
From source file:it.webappcommon.lib.dao.AbstractBaseDAO.java
/** * Si preoccupa di caricare i dati base di tutti gli AbstractDataMappingBase * //from w w w .j av a 2 s . co m * @param oggettoDaCaricare * @param rs * @throws Exception */ protected void fillerBase(T oggettoDaCaricare, ResultSet rs) throws Exception { // Campi standard per Abstract if (this.getCampoDataCreazione() != null) { oggettoDaCaricare.setDataCreazione(rs.getTimestamp(this.getCampoDataCreazione())); } if (this.getCampoIDUtenteCreazione() != null) { oggettoDaCaricare.setIdUtenteCreazione(rs.getInt(this.getCampoIDUtenteCreazione())); } if (this.getCampoDataModifica() != null) { oggettoDaCaricare.setDataModifica(rs.getTimestamp(this.getCampoDataModifica())); } if (this.getCampoIDUtenteModifica() != null) { oggettoDaCaricare.setIdUtenteModifica(rs.getInt(this.getCampoIDUtenteModifica())); } if (this.getCampoDataCancellazione() != null) { oggettoDaCaricare.setDataCancellazione(rs.getTimestamp(this.getCampoDataCancellazione())); } if (this.getCampoIDUtenteCancellazione() != null) { oggettoDaCaricare.setIdUtenteCancellazione(rs.getInt(this.getCampoIDUtenteCancellazione())); } oggettoDaCaricare.setUiUtentePrivilegiato(uiUtentePrivilegiato); }
From source file:org.opennms.ng.services.poller.Poller.java
private int scheduleMatchingServices(String criteria) { String sql = "SELECT ifServices.nodeId AS nodeId, node.nodeLabel AS nodeLabel, ifServices.ipAddr AS ipAddr, " + "ifServices.serviceId AS serviceId, service.serviceName AS serviceName, ifServices.status as status, " + "outages.svcLostEventId AS svcLostEventId, events.eventUei AS svcLostEventUei, " + "outages.ifLostService AS ifLostService, outages.ifRegainedService AS ifRegainedService " + "FROM ifServices " + "JOIN node ON ifServices.nodeId = node.nodeId " + "JOIN service ON ifServices.serviceId = service.serviceId " + "LEFT OUTER JOIN outages ON " + "ifServices.nodeId = outages.nodeId AND " + "ifServices.ipAddr = outages.ipAddr AND " + "ifServices.serviceId = outages.serviceId AND " + "ifRegainedService IS NULL " + "LEFT OUTER JOIN events ON outages.svcLostEventId = events.eventid " + "WHERE ifServices.status in ('A','N')" + (criteria == null ? "" : " AND " + criteria); final AtomicInteger count = new AtomicInteger(0); Querier querier = new Querier(m_dataSource, sql) { @Override/*from ww w. j a v a 2s . c om*/ public void processRow(ResultSet rs) throws SQLException { if (scheduleService(rs.getInt("nodeId"), rs.getString("nodeLabel"), rs.getString("ipAddr"), rs.getString("serviceName"), "A".equals(rs.getString("status")), (Number) rs.getObject("svcLostEventId"), rs.getTimestamp("ifLostService"), rs.getString("svcLostEventUei"))) { count.incrementAndGet(); } } }; querier.execute(); return count.get(); }
From source file:it.cnr.icar.eric.server.persistence.rdb.SubscriptionDAO.java
@SuppressWarnings("unchecked") protected void loadObject(Object obj, ResultSet rs) throws RegistryException { try {// w ww.j a v a2s . c om if (!(obj instanceof SubscriptionType)) { throw new RegistryException(ServerResourceBundle.getInstance() .getString("message.SubscriptionTypeExpected", new Object[] { obj })); } SubscriptionType ebSubscriptionType = (SubscriptionType) obj; super.loadObject(obj, rs); String selector = rs.getString("selector"); ebSubscriptionType.setSelector(selector); // Need to work around a bug in PostgreSQL and loading of // ClassificationScheme data from NIST tests try { Timestamp endTimestamp = rs.getTimestamp("endTime"); if (endTimestamp != null) { // Calendar calendar = Calendar.getInstance(); // calendar.setTimeInMillis(endTime.getTime()); GregorianCalendar calendar = new GregorianCalendar(); calendar.setTimeInMillis(endTimestamp.getTime()); XMLGregorianCalendar endTime = DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar); ebSubscriptionType.setEndTime(endTime); } } catch (StringIndexOutOfBoundsException e) { String id = rs.getString("id"); log.error(ServerResourceBundle.getInstance().getString("message.SubscriptionDAOId", new Object[] { id }), e); } String notificationIntervalString = rs.getString("notificationInterval"); if (notificationIntervalString != null) { Duration notificationInterval = DatatypeFactory.newInstance() .newDuration(notificationIntervalString); ebSubscriptionType.setNotificationInterval(notificationInterval); } // Need to work around a bug in PostgreSQL and loading of // ClassificationScheme data from NIST tests try { Timestamp startTimestamp = rs.getTimestamp("startTime"); if (startTimestamp != null) { // Calendar calendar = Calendar.getInstance(); // calendar.setTimeInMillis(startTime.getTime()); GregorianCalendar calendar = new GregorianCalendar(); calendar.setTimeInMillis(startTimestamp.getTime()); XMLGregorianCalendar startTime = DatatypeFactory.newInstance() .newXMLGregorianCalendar(new GregorianCalendar()); ebSubscriptionType.setStartTime(startTime); } } catch (StringIndexOutOfBoundsException e) { String id = rs.getString("id"); log.error(ServerResourceBundle.getInstance().getString("message.SubscriptionDAOId", new Object[] { id }), e); } NotifyActionDAO notifyActionDAO = new NotifyActionDAO(context); notifyActionDAO.setParent(ebSubscriptionType); @SuppressWarnings("rawtypes") List notifyActions = notifyActionDAO.getByParent(); if (notifyActions != null) { bu.getActionTypeListFromElements(ebSubscriptionType.getAction()).addAll(notifyActions); } } catch (SQLException e) { log.error(ServerResourceBundle.getInstance().getString("message.CaughtException1"), e); throw new RegistryException(e); } catch (DatatypeConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.its.core.local.hezhou.task.ExportImageFilesReadTask.java
private List<VehicelRecordBean> getExportRecordList(Connection conn) throws Exception { List<VehicelRecordBean> recordList = new ArrayList<VehicelRecordBean>(); PreparedStatement preStatement = null; ResultSet rs = null; try {/*from w ww . j a va 2s . c om*/ log.debug("" + this.getSelecImageFileRecordSql()); preStatement = conn.prepareStatement(this.getSelecImageFileRecordSql()); rs = preStatement.executeQuery(); while (rs.next()) { VehicelRecordBean record = new VehicelRecordBean(); record.setId(rs.getLong("ID")); record.setDeviceIp(rs.getString("DeviceIP")); record.setPlate(rs.getString("LicenseNumber")); record.setPlateColorCode(rs.getString("LicenseColor")); record.setDirectionCode(rs.getString("Direction")); record.setCatchTime(rs.getTimestamp("CatchDate")); record.setDrivewayNo(rs.getString("RoadId")); record.setSpeed(rs.getString("Speed")); record.setFeatureImagePath(rs.getString("ImagePath")); recordList.add(record); } } catch (Exception ex) { log.error(ex.getMessage(), ex); throw ex; } finally { DatabaseHelper.close(rs, preStatement); } return recordList; }
From source file:com.oltpbenchmark.benchmarks.seats.SEATSProfile.java
private final void loadConfigProfile(ResultSet vt) throws SQLException { boolean adv = vt.next(); assert (adv); int col = 1;// w ww. ja v a2 s .co m this.scale_factor = vt.getDouble(col++); JSONUtil.fromJSONString(this.airport_max_customer_id, vt.getString(col++)); this.flight_start_date.setTime(vt.getTimestamp(col++).getTime()); this.flight_upcoming_date = vt.getTimestamp(col++); this.flight_past_days = vt.getLong(col++); this.flight_future_days = vt.getLong(col++); this.flight_upcoming_offset = vt.getLong(col++); this.reservation_upcoming_offset = vt.getLong(col++); this.num_reservations = vt.getLong(col++); if (LOG.isDebugEnabled()) LOG.debug(String.format("Loaded %s data", SEATSConstants.TABLENAME_CONFIG_PROFILE)); }