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:com.opensymphony.module.propertyset.database.JDBCPropertySet.java
protected Object get(int type, String key) throws PropertyException { String sql = "SELECT " + colItemType + ", " + colString + ", " + colDate + ", " + colData + ", " + colFloat + ", " + colNumber + " FROM " + tableName + " WHERE " + colItemKey + " = ? AND " + colGlobalKey + " = ?"; Object o = null;/*from ww w.j ava 2 s .c o m*/ Connection conn = null; try { conn = ds.getConnection(); PreparedStatement ps = conn.prepareStatement(sql); ps.setString(1, key); ps.setString(2, globalKey); int propertyType; ResultSet rs = ps.executeQuery(); if (rs.next()) { propertyType = rs.getInt(colItemType); if (propertyType != type) { throw new InvalidPropertyTypeException(); } switch (type) { case PropertySet.BOOLEAN: int boolVal = rs.getInt(colNumber); o = new Boolean(boolVal == 1); break; case PropertySet.DATA: o = rs.getBytes(colData); break; case PropertySet.DATE: o = rs.getTimestamp(colDate); break; case PropertySet.DOUBLE: o = new Double(rs.getDouble(colFloat)); break; case PropertySet.INT: o = new Integer(rs.getInt(colNumber)); break; case PropertySet.LONG: o = new Long(rs.getLong(colNumber)); break; case PropertySet.STRING: o = rs.getString(colString); break; default: throw new InvalidPropertyTypeException("JDBCPropertySet doesn't support this type yet."); } } rs.close(); ps.close(); } catch (SQLException e) { throw new PropertyException(e.getMessage()); } catch (NumberFormatException e) { throw new PropertyException(e.getMessage()); } finally { closeConnection(conn); } return o; }
From source file:com.snowy.data.java
public HashMap<Integer, String> chatsSince(int id, int lastMessageid) { HashMap<Integer, String> hm = new HashMap<>(); try {/*from www .java2 s . c o m*/ PreparedStatement ps = con.prepareStatement( "select Timestamp,Message,sender,Message_id from chat where GameId =? and Message_id > ?"); ps.setInt(1, id); ps.setInt(2, lastMessageid); ResultSet rs = ps.executeQuery(); rs.beforeFirst(); while (rs.next()) { LocalDateTime t = rs.getTimestamp("Timestamp").toLocalDateTime(); String time = String.format("%02d:%02d", t.getHour(), t.getMinute()); hm.put(rs.getInt("Message_id"), time + " " + rs.getString("sender") + ": " + rs.getString("Message") + "\n"); } //ps.close(); //rs.close(); } catch (SQLException ex) { Logger.getLogger(data.class.getName()).log(Level.SEVERE, null, ex); } return hm; }
From source file:com.concursive.connect.web.modules.documents.dao.FileFolder.java
/** * Description of the Method//w ww. j a va 2s.com * * @param rs Description of the Parameter * @throws SQLException Description of the Exception */ private void buildRecord(ResultSet rs) throws SQLException { id = rs.getInt("folder_id"); linkModuleId = rs.getInt("link_module_id"); linkItemId = rs.getInt("link_item_id"); subject = rs.getString("subject"); description = rs.getString("description"); parentId = DatabaseUtils.getInt(rs, "parent_id"); entered = rs.getTimestamp("entered"); enteredBy = rs.getInt("enteredby"); modified = rs.getTimestamp("modified"); modifiedBy = rs.getInt("modifiedby"); display = DatabaseUtils.getInt(rs, "display"); }
From source file:com.webpagebytes.wpbsample.database.WPBDatabase.java
public List<DepositWithdrawal> getDepositsWithdrawalsForUser(int user_id, DepositWithdrawal.OperationType type, Date date, int page, int pageSize) throws SQLException { Connection connection = getConnection(); List<DepositWithdrawal> result = new ArrayList<DepositWithdrawal>(); PreparedStatement statement = null; try {/*from w ww.java2s . co m*/ statement = connection.prepareStatement(GET_ALL_DEPOSITWITHDRAWAL_FOR_USER_STATEMENT); statement.setTimestamp(1, new Timestamp(date.getTime())); statement.setInt(2, user_id); if (type == OperationType.DEPOSIT) { statement.setInt(3, ACCOUNT_OPERATION_DEPOSIT); } else { statement.setInt(3, ACCOUNT_OPERATION_WITHDRAWAL); } if (page <= 0) page = 1; statement.setInt(4, (page - 1) * (pageSize - 1)); // the offset statement.setInt(5, pageSize); // how many records ResultSet rs = statement.executeQuery(); while (rs.next()) { DepositWithdrawal item = new DepositWithdrawal(); item.setId(rs.getLong(1)); item.setUser_id(rs.getInt(2)); item.setType(type); item.setAmount(rs.getLong(4)); item.setDate(rs.getTimestamp(5)); result.add(item); } } catch (SQLException e) { throw e; } finally { if (statement != null) { statement.close(); } if (connection != null) { connection.close(); } } return result; }
From source file:com.webpagebytes.wpbsample.database.WPBDatabase.java
public List<AccountOperation> getAccountOperationsForUser(int user_id, Date date, int count) throws SQLException { Connection connection = getConnection(); List<AccountOperation> result = new ArrayList<AccountOperation>(); PreparedStatement statement = null; try {/*from ww w . j a v a2s . c o m*/ statement = connection.prepareStatement(GET_ALL_ACCOUNTOPERATIONS_FOR_USER_STATEMENT); statement.setTimestamp(1, new Timestamp(date.getTime())); statement.setInt(2, user_id); statement.setInt(3, user_id); statement.setInt(4, user_id); statement.setInt(5, count); // how many records ResultSet rs = statement.executeQuery(); while (rs.next()) { AccountOperation item = new AccountOperation(); item.setId(rs.getLong(1)); item.setUser_id(rs.getInt(2)); item.setType(rs.getInt(3)); item.setAmount(rs.getLong(4)); item.setDate(rs.getTimestamp(5)); item.setSource_user_id(rs.getInt(6)); item.setDestination_user_id(rs.getInt(7)); item.setSourceUserName(rs.getString(8)); item.setDestinationUserName(rs.getString(9)); result.add(item); } } catch (SQLException e) { throw e; } finally { if (statement != null) { statement.close(); } if (connection != null) { connection.close(); } } return result; }
From source file:com.sfs.whichdoctor.dao.QualificationDAOImpl.java
/** * Load the qualification bean from the result set. * * @param rs the rs/*w w w. j av a 2 s. co m*/ * @return the qualification bean * @throws SQLException the sQL exception */ private QualificationBean loadQualification(final ResultSet rs) throws SQLException { QualificationBean qualification = new QualificationBean(); qualification.setId(rs.getInt("QualificationId")); qualification.setGUID(rs.getInt("GUID")); qualification.setReferenceGUID(rs.getInt("ReferenceGUID")); qualification.setQualification(rs.getString("Qualification")); qualification.setQualificationType(rs.getString("QualificationType")); qualification.setQualificationSubType(rs.getString("QualificationSubType")); qualification.setInstitution(rs.getString("Institution")); qualification.setHonor(rs.getString("Honor")); qualification.setYear(rs.getInt("Year")); qualification.setCountry(rs.getString("Country")); qualification.setActive(rs.getBoolean("Active")); try { qualification.setCreatedDate(rs.getTimestamp("CreatedDate")); } catch (SQLException sqe) { dataLogger.debug("Error loading CreatedDate: " + sqe.getMessage()); } qualification.setCreatedBy(rs.getString("CreatedBy")); try { qualification.setModifiedDate(rs.getTimestamp("ModifiedDate")); } catch (SQLException sqe) { dataLogger.debug("Error loading ModifiedDate: " + sqe.getMessage()); } qualification.setModifiedBy(rs.getString("ModifiedBy")); return qualification; }
From source file:com.sfs.dao.FinancialTypeDAOImpl.java
/** * Load details.//from w w w. j a v a 2 s.c o m * * @param rs the rs * * @return the financial type bean * * @throws SQLException the SQL exception */ private FinancialTypeBean loadDetails(final ResultSet rs) throws SQLException { FinancialTypeBean financialType = new FinancialTypeBean(); financialType.setFinancialTypeId(rs.getInt("FinancialTypeId")); financialType.setObject(rs.getString("Object")); financialType.setName(rs.getString("Name")); financialType.setClassName(rs.getString("Class")); financialType.setAbbreviation(rs.getString("Abbreviation")); financialType.setSecurity(rs.getString("Security")); financialType.setLdapMapping(1, rs.getString("LdapMapping")); financialType.setLdapMapping(2, rs.getString("SecondLdapMapping")); financialType.setLdapMapping(3, rs.getString("ThirdLdapMapping")); financialType.setValue(rs.getDouble("Value")); financialType.setDescription(rs.getString("Description")); financialType.setCreated(rs.getTimestamp("Created")); financialType.setCreatedBy(rs.getString("CreatedBy")); financialType.setModified(rs.getTimestamp("Modified")); financialType.setModifiedBy(rs.getString("ModifiedBy")); if (financialType.getCreatedBy() != null && this.userDAO != null) { try { financialType.setCreatedByUser(this.userDAO.loadCached(financialType.getCreatedBy())); } catch (Exception e) { dataLogger.info("Could not load CreatedBy UserBean for FinancialTypeId = " + financialType.getFinancialTypeId()); } } if (financialType.getModifiedBy() != null && this.userDAO != null) { try { financialType.setModifiedByUser(this.userDAO.loadCached(financialType.getModifiedBy())); } catch (Exception e) { dataLogger.info("Could not load ModifiedBy UserBean for FinancialTypeId = " + financialType.getFinancialTypeId()); } } return financialType; }
From source file:eionet.meta.dao.mysql.SchemaSetDAOImpl.java
@Override public List<SchemaSet> getSchemaSets(List<Integer> ids) { String sql = "SELECT * FROM T_SCHEMA_SET WHERE SCHEMA_SET_ID IN (:ids)"; Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("ids", ids); List<SchemaSet> items = getNamedParameterJdbcTemplate().query(sql, parameters, new RowMapper<SchemaSet>() { @Override/*w ww . jav a 2 s .c o m*/ public SchemaSet mapRow(ResultSet rs, int rowNum) throws SQLException { SchemaSet ss = new SchemaSet(); ss.setId(rs.getInt("SCHEMA_SET_ID")); ss.setIdentifier(rs.getString("IDENTIFIER")); ss.setContinuityId(rs.getString("CONTINUITY_ID")); ss.setRegStatus(RegStatus.fromString(rs.getString("REG_STATUS"))); ss.setWorkingCopy(rs.getBoolean("WORKING_COPY")); ss.setWorkingUser(rs.getString("WORKING_USER")); ss.setDateModified(rs.getTimestamp("DATE_MODIFIED")); ss.setUserModified(rs.getString("USER_MODIFIED")); ss.setComment(rs.getString("COMMENT")); ss.setCheckedOutCopyId(rs.getInt("CHECKEDOUT_COPY_ID")); ss.setStatusModified(rs.getTimestamp("STATUS_MODIFIED")); return ss; } }); return items; }
From source file:eionet.meta.dao.mysql.SchemaSetDAOImpl.java
/** * @see eionet.meta.dao.ISchemaSetDAO#getSchemaSetVersions(String, java.lang.String, int...) */// w w w. j a va 2 s . c o m @Override public List<SchemaSet> getSchemaSetVersions(String userName, String continuityId, int... excludeIds) { if (StringUtils.isBlank(continuityId)) { throw new IllegalArgumentException("Continuity id must not be blank!"); } String sql = "select * from T_SCHEMA_SET where WORKING_COPY=false and CONTINUITY_ID=:continuityId"; Map<String, Object> params = new HashMap<String, Object>(); params.put("continuityId", continuityId); if (StringUtils.isBlank(userName)) { sql += " and REG_STATUS=:regStatus"; params.put("regStatus", RegStatus.RELEASED.toString()); } if (excludeIds != null && excludeIds.length > 0) { sql += " and SCHEMA_SET_ID not in (:excludeIds)"; params.put("excludeIds", Arrays.asList(ArrayUtils.toObject(excludeIds))); } sql += " order by SCHEMA_SET_ID desc"; List<SchemaSet> resultList = getNamedParameterJdbcTemplate().query(sql, params, new RowMapper<SchemaSet>() { @Override public SchemaSet mapRow(ResultSet rs, int rowNum) throws SQLException { SchemaSet ss = new SchemaSet(); ss.setId(rs.getInt("SCHEMA_SET_ID")); ss.setIdentifier(rs.getString("IDENTIFIER")); ss.setContinuityId(rs.getString("CONTINUITY_ID")); ss.setRegStatus(RegStatus.fromString(rs.getString("REG_STATUS"))); ss.setWorkingCopy(rs.getBoolean("WORKING_COPY")); ss.setWorkingUser(rs.getString("WORKING_USER")); ss.setDateModified(rs.getTimestamp("DATE_MODIFIED")); ss.setUserModified(rs.getString("USER_MODIFIED")); ss.setComment(rs.getString("COMMENT")); ss.setCheckedOutCopyId(rs.getInt("CHECKEDOUT_COPY_ID")); ss.setStatusModified(rs.getTimestamp("STATUS_MODIFIED")); return ss; } }); return resultList; }
From source file:net.pms.dlna.DLNAMediaDatabase.java
public ArrayList<File> getFiles(String sql) { ArrayList<File> list = new ArrayList<File>(); Connection conn = null;//from w w w.j a v a2 s .c o m ResultSet rs = null; PreparedStatement ps = null; try { conn = getConnection(); ps = conn.prepareStatement(sql.toLowerCase().startsWith("select") ? sql : ("SELECT FILENAME, MODIFIED FROM FILES WHERE " + sql)); rs = ps.executeQuery(); while (rs.next()) { String filename = rs.getString("FILENAME"); long modified = rs.getTimestamp("MODIFIED").getTime(); File file = new File(filename); if (file.exists() && file.lastModified() == modified) { list.add(file); } } } catch (SQLException se) { logger.error(null, se); return null; } finally { close(rs); close(ps); close(conn); } return list; }