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:io.github.sislivros.persistencia.UsuarioBdDao.java
public Usuario preencherObjeto(ResultSet rs) { Usuario usuario = new Usuario(); try {//from w ww . j a va 2s . co m usuario.setApelido(rs.getString("apelido")); usuario.setDataNascimento(rs.getDate("data_nascimento")); usuario.setCidade(rs.getString("cidade")); usuario.setEstado(rs.getString("estado")); usuario.setEmail(rs.getString("email")); usuario.setFotoPerfil(rs.getString("foto_perfil")); usuario.setFotoCapa(rs.getString("foto_capa")); usuario.setNome(rs.getString("nome")); usuario.setSenha(rs.getString("senha")); usuario.setId(rs.getInt("id")); usuario.setDataCadastro(rs.getTimestamp("data_cadastro")); for (TipoUsuario t : TipoUsuario.values()) { if (t.id == rs.getInt("tipo")) { usuario.setTipo(t); break; } } } catch (SQLException ex) { ex.printStackTrace(); } return usuario; }
From source file:org.waarp.common.database.data.AbstractDbData.java
/** * Get one value into DbValue from ResultSet * /* w ww.jav a 2s. c o m*/ * @param rs * @param value * @throws WaarpDatabaseSqlException */ static public void getTrueValue(ResultSet rs, DbValue value) throws WaarpDatabaseSqlException { try { switch (value.type) { case Types.VARCHAR: value.value = rs.getString(value.column); break; case Types.LONGVARCHAR: value.value = rs.getString(value.column); break; case Types.BIT: value.value = rs.getBoolean(value.column); break; case Types.TINYINT: value.value = rs.getByte(value.column); break; case Types.SMALLINT: value.value = rs.getShort(value.column); break; case Types.INTEGER: value.value = rs.getInt(value.column); break; case Types.BIGINT: value.value = rs.getLong(value.column); break; case Types.REAL: value.value = rs.getFloat(value.column); break; case Types.DOUBLE: value.value = rs.getDouble(value.column); break; case Types.VARBINARY: value.value = rs.getBytes(value.column); break; case Types.DATE: value.value = rs.getDate(value.column); break; case Types.TIMESTAMP: value.value = rs.getTimestamp(value.column); break; case Types.CLOB: value.value = rs.getClob(value.column).getCharacterStream(); break; case Types.BLOB: value.value = rs.getBlob(value.column).getBinaryStream(); break; default: throw new WaarpDatabaseSqlException("Type not supported: " + value.type + " for " + value.column); } } catch (SQLException e) { DbSession.error(e); throw new WaarpDatabaseSqlException("Getting values in error: " + value.type + " for " + value.column, e); } }
From source file:com.cloudera.sqoop.manager.SqlManager.java
@Override /**/*from w w w . ja v a 2s . c o m*/ * {@inheritDoc} */ public Timestamp getCurrentDbTimestamp() { release(); // Release any previous ResultSet. Statement s = null; ResultSet rs = null; try { Connection c = getConnection(); s = c.createStatement(); rs = s.executeQuery(getCurTimestampQuery()); if (rs == null || !rs.next()) { return null; // empty ResultSet. } return rs.getTimestamp(1); } catch (SQLException sqlE) { LOG.warn("SQL exception accessing current timestamp: " + sqlE); return null; } finally { try { if (null != rs) { rs.close(); } } catch (SQLException sqlE) { LOG.warn("SQL Exception closing resultset: " + sqlE); } try { if (null != s) { s.close(); } } catch (SQLException sqlE) { LOG.warn("SQL Exception closing statement: " + sqlE); } } }
From source file:cz.incad.kramerius.processes.impl.DatabaseProcessManager.java
private LRProcess processFromResultSet(ResultSet rs) throws SQLException { // CREATE TABLE PROCESSES(DEFID VARCHAR, UUID VARCHAR ,PID // VARCHAR,STARTED timestamp, STATUS int String definitionId = rs.getString("DEFID"); String pid = rs.getString("PID"); String uuid = rs.getString("UUID"); int status = rs.getInt("STATUS"); Timestamp planned = rs.getTimestamp("PLANNED"); Timestamp started = rs.getTimestamp("STARTED"); Timestamp finished = rs.getTimestamp("FINISHED"); String name = rs.getString("PNAME"); String params = rs.getString("PARAMS"); String token = rs.getString("TOKEN"); String authToken = rs.getString("AUTH_TOKEN"); int startedBy = rs.getInt("STARTEDBY"); String loginname = rs.getString("LOGINNAME"); String firstname = rs.getString("FIRSTNAME"); String surname = rs.getString("SURNAME"); String userKey = rs.getString("USER_KEY"); String paramsMapping = rs.getString("params_mapping"); int batchStatus = rs.getInt("BATCH_STATUS"); String ipAddr = rs.getString("IP_ADDR"); LRProcessDefinition definition = this.lrpdm.getLongRunningProcessDefinition(definitionId); if (definition == null) { throw new RuntimeException("cannot find definition '" + definitionId + "'"); }/*from w w w. j ava 2s. c o m*/ LRProcess process = definition.loadProcess(uuid, pid, planned != null ? planned.getTime() : 0, States.load(status), BatchStates.load(batchStatus), name); process.setGroupToken(token); process.setAuthToken(authToken); if (started != null) process.setStartTime(started.getTime()); if (params != null) { String[] paramsArray = params.split(","); process.setParameters(Arrays.asList(paramsArray)); } process.setFirstname(firstname); process.setSurname(surname); process.setLoginname(loginname); process.setLoggedUserKey(userKey); if (paramsMapping != null) { Properties props = PropertiesStoreUtils.loadProperties(paramsMapping); process.setParametersMapping(props); } if (finished != null) { process.setFinishedTime(finished.getTime()); } if (ipAddr != null) { process.setPlannedIPAddress(ipAddr); } return process; }
From source file:eionet.cr.dao.readers.PostHarvestScriptDTOReader.java
@Override public void readRow(ResultSet rs) throws SQLException, ResultSetReaderException { String targetSourceUrl = rs.getString("TARGET_SOURCE_URL"); String targetTypeUrl = rs.getString("TARGET_TYPE_URL"); TargetType targetType = null;//from ww w .j ava 2 s. c o m String targetUrl = null; if (!StringUtils.isBlank(targetSourceUrl)) { targetType = TargetType.SOURCE; targetUrl = targetSourceUrl; } else if (!StringUtils.isBlank(targetTypeUrl)) { targetType = TargetType.TYPE; targetUrl = targetTypeUrl; } PostHarvestScriptDTO dto = new PostHarvestScriptDTO(); dto.setId(rs.getInt("POST_HARVEST_SCRIPT_ID")); dto.setTargetType(targetType); dto.setTargetUrl(targetUrl); dto.setTitle(rs.getString("TITLE")); dto.setScript(rs.getString("SCRIPT")); dto.setPosition(rs.getInt("POSITION_NUMBER")); dto.setActive(YesNoBoolean.parse(rs.getString("ACTIVE"))); dto.setRunOnce(YesNoBoolean.parse(rs.getString("RUN_ONCE"))); dto.setLastModified(rs.getTimestamp("LAST_MODIFIED")); resultList.add(dto); }
From source file:dsd.dao.CalculatedDataDAO.java
public static ArrayList<CalculatedData> GetAllForPeriod(Calendar startDate, Calendar endDate, eCalculatedDataType dataType) {/* ww w. j a va 2s . com*/ try { Connection con = DAOProvider.getDataSource().getConnection(); ArrayList<CalculatedData> calculatedDataList = new ArrayList<CalculatedData>(); try { String tableName = GetTableNameForDataType(dataType); Object[] parameters = new Object[2]; parameters[0] = new Timestamp(startDate.getTimeInMillis()); parameters[1] = new Timestamp(endDate.getTimeInMillis()); ResultSet results = DAOProvider.SelectTableSecure(tableName, "*", " timestamp >= ? and timestamp <= ? ", "", con, parameters); while (results.next()) { CalculatedData dataTuple = new CalculatedData(); dataTuple.setCalulcatedDataID(results.getLong("ID")); dataTuple.setWindSpeed(results.getFloat(fields[0])); dataTuple.setWindDirection(results.getFloat(fields[1])); dataTuple.setWindSpeedMax(results.getFloat(fields[2])); dataTuple.setWindDirectionMax(results.getFloat(fields[3])); dataTuple.setHydrometer(results.getFloat(fields[4])); dataTuple.setHydrometerVariance(results.getFloat(fields[5])); dataTuple.setSonar(results.getFloat(fields[6])); dataTuple.setSonarVariance(results.getFloat(fields[7])); dataTuple.setSonarPercCorrect(results.getFloat(fields[8])); dataTuple.setSonarPercWrong(results.getFloat(fields[9])); dataTuple.setSonarPercOutOfWater(results.getFloat(fields[10])); dataTuple.setSonarPercError(results.getFloat(fields[11])); dataTuple.setSonarPercUncertain(results.getFloat(fields[12])); dataTuple.setSafetyFactor00(results.getFloat(fields[13])); dataTuple.setSafetyFactor01(results.getFloat(fields[14])); dataTuple.setSafetyFactor10(results.getFloat(fields[15])); dataTuple.setSafetyFactor11(results.getFloat(fields[16])); dataTuple.setWaterSpeed(results.getFloat(fields[17])); dataTuple.setWaterFlowRate(results.getFloat(fields[18])); dataTuple.setTimestamp(results.getTimestamp(fields[19]).getTime()); calculatedDataList.add(dataTuple); } } catch (Exception exc) { exc.printStackTrace(); } con.close(); return calculatedDataList; } catch (Exception exc) { exc.printStackTrace(); } return null; }
From source file:com.sfs.whichdoctor.dao.PhoneDAOImpl.java
/** * Load phone bean from the result set.//from w w w .j av a 2 s. c om * * @param rs the rs * @return the phone bean * @throws SQLException the sQL exception */ private PhoneBean loadPhone(final ResultSet rs) throws SQLException { PhoneBean phoneNumber = new PhoneBean(); phoneNumber.setId(rs.getInt("PhoneId")); phoneNumber.setGUID(rs.getInt("GUID")); phoneNumber.setReferenceGUID(rs.getInt("ReferenceGUID")); phoneNumber.setContactType(rs.getString("ContactType")); phoneNumber.setDescription(rs.getString("Description")); phoneNumber.setNumber(rs.getString("PhoneNum")); phoneNumber.setExtension(rs.getString("Extension")); phoneNumber.setAreaCode(rs.getInt("AreaCode")); phoneNumber.setCountryCode(rs.getInt("CountryCode")); phoneNumber.setPrimary(rs.getBoolean("PrimaryPhone")); phoneNumber.setActive(rs.getBoolean("Active")); try { phoneNumber.setCreatedDate(rs.getTimestamp("CreatedDate")); } catch (SQLException sqe) { dataLogger.debug("Error reading CreatedDate: " + sqe.getMessage()); } phoneNumber.setCreatedBy(rs.getString("CreatedBy")); try { phoneNumber.setModifiedDate(rs.getTimestamp("ModifiedDate")); } catch (SQLException sqe) { dataLogger.debug("Error reading ModifiedDate: " + sqe.getMessage()); } phoneNumber.setModifiedBy(rs.getString("ModifiedBy")); try { phoneNumber.setExportedDate(rs.getTimestamp("ExportedDate")); } catch (SQLException sqe) { dataLogger.debug("Error reading ExportedDate: " + sqe.getMessage()); } phoneNumber.setExportedBy(rs.getString("ExportedBy")); return phoneNumber; }
From source file:eionet.cr.dao.readers.HarvestScriptDTOReader.java
@Override public void readRow(ResultSet rs) throws SQLException, ResultSetReaderException { String targetSourceUrl = rs.getString("TARGET_SOURCE_URL"); String targetTypeUrl = rs.getString("TARGET_TYPE_URL"); TargetType targetType = null;/* w w w. j a v a2 s.co m*/ String targetUrl = null; if (!StringUtils.isBlank(targetSourceUrl)) { targetType = TargetType.SOURCE; targetUrl = targetSourceUrl; } else if (!StringUtils.isBlank(targetTypeUrl)) { targetType = TargetType.TYPE; targetUrl = targetTypeUrl; } HarvestScriptDTO dto = new HarvestScriptDTO(); dto.setId(rs.getInt("POST_HARVEST_SCRIPT_ID")); dto.setTargetType(targetType); dto.setTargetUrl(targetUrl); dto.setTitle(rs.getString("TITLE")); dto.setScript(rs.getString("SCRIPT")); dto.setPosition(rs.getInt("POSITION_NUMBER")); dto.setActive(YesNoBoolean.parse(rs.getString("ACTIVE"))); dto.setRunOnce(YesNoBoolean.parse(rs.getString("RUN_ONCE"))); dto.setLastModified(rs.getTimestamp("LAST_MODIFIED")); try { dto.setPhase(Phase.valueOf(rs.getString("PHASE"))); } catch (Exception e) { dto.setPhase(null); } resultList.add(dto); }
From source file:com.sfs.whichdoctor.dao.MemoDAOImpl.java
/** * Load the MemoBean.// w w w . j av a 2s. c o m * * @param rs the rs * @param fullResults the full results * @return the memo bean * @throws SQLException the sQL exception */ private MemoBean loadMemo(final ResultSet rs, final boolean fullResults) throws SQLException { final MemoBean memo = new MemoBean(); memo.setId(rs.getInt("MemoId")); memo.setGUID(rs.getInt("GUID")); memo.setReferenceGUID(rs.getInt("ReferenceGUID")); memo.setType(rs.getString("Type")); memo.setObjectType(rs.getString("ObjectType")); memo.setSecurity(rs.getString("Security")); memo.setPriority(rs.getInt("Priority")); if (fullResults) { memo.setMessage(rs.getString("Message")); } try { memo.setExpires(rs.getDate("Expires")); } catch (SQLException sqe) { dataLogger.debug("Error loading Expires: " + sqe.getMessage()); } memo.setActive(rs.getBoolean("Active")); try { memo.setCreatedDate(rs.getTimestamp("CreatedDate")); } catch (SQLException sqe) { dataLogger.debug("Error reading CreatedDate: " + sqe.getMessage()); } memo.setCreatedBy(rs.getString("CreatedBy")); try { memo.setModifiedDate(rs.getTimestamp("ModifiedDate")); } catch (SQLException sqe) { dataLogger.debug("Error reading ModifiedDate: " + sqe.getMessage()); } memo.setModifiedBy(rs.getString("ModifiedBy")); try { memo.setExportedDate(rs.getTimestamp("ExportedDate")); } catch (SQLException sqe) { dataLogger.debug("Error reading ExportedDate: " + sqe.getMessage()); } memo.setExportedBy(rs.getString("ExportedBy")); if (fullResults) { /* Set the user details objects */ UserBean user = new UserBean(); user.setDN(rs.getString("CreatedBy")); user.setPreferredName(rs.getString("CreatedFirstName")); user.setLastName(rs.getString("CreatedLastName")); memo.setCreatedUser(user); UserBean modified = new UserBean(); modified.setDN(rs.getString("ModifiedBy")); modified.setPreferredName(rs.getString("ModifiedFirstName")); modified.setLastName(rs.getString("ModifiedLastName")); memo.setModifiedUser(modified); } return memo; }
From source file:com.snowy.data.java
public java.sql.Timestamp getCurrentSqlTimestamp() { java.sql.Timestamp dd = null; try {//from w w w . j a v a 2 s .co m ResultSet rs = con.prepareStatement("select current_timestamp() as timestamp").executeQuery(); rs.last(); dd = rs.getTimestamp("timestamp"); //ps.close(); //rs.close(); } catch (SQLException ex) { Logger.getLogger(data.class.getName()).log(Level.SEVERE, null, ex); } return dd; }