List of usage examples for java.sql ResultSet getDate
java.sql.Date getDate(String columnLabel) throws SQLException;
ResultSet
object as a java.sql.Date
object in the Java programming language. From source file:mvc.dao.TarefaDAO.java
public List<Tarefa> listarTarefas() { List<Tarefa> listaTarefas = new ArrayList<Tarefa>(); String sql = "select * from tarefas order by descricao"; try (PreparedStatement stmt = connection.prepareStatement(sql)) { ResultSet rs = stmt.executeQuery(); while (rs.next()) { Tarefa tarefa = new Tarefa(); tarefa.setId(rs.getLong("id")); tarefa.setDescricao(rs.getString("descricao")); tarefa.setFinalizado(rs.getBoolean("finalizado")); //montando data Calendar data = Calendar.getInstance(); if (rs.getDate("dataFinalizacao") != null) { data.setTime(rs.getDate("dataFinalizacao")); tarefa.setDataFinalizacao(data); }//from w w w. j av a2 s .co m listaTarefas.add(tarefa); } } catch (SQLException e) { throw new RuntimeException(e); } return listaTarefas; }
From source file:com.havoc.hotel.admin.dao.impl.CheckinDAOImpl.java
private Checkin mapData(ResultSet rs) throws SQLException { Checkin c = new Checkin(); c.setCheckinId(rs.getInt("checkin_id")); Booking b = new Booking(); b.setBookingId(rs.getInt("booking_id")); b.setFirstName(rs.getString("first_name")); b.setLastName(rs.getString("last_name")); Room r = new Room(); r.setRoomPrice(rs.getInt("room_price")); r.setRoomNumber(rs.getInt("room_number")); b.setRoom(r);/* ww w . j ava 2s . co m*/ b.setCheckinDate(rs.getDate("checkin_date")); b.setTotalDays(rs.getInt("total_days")); b.setTotalNights(rs.getInt("total_nights")); b.setTotalPrice(rs.getInt("total_price")); b.setCheckoutDate(rs.getDate("checkout_date")); c.setBooking(b); return c; }
From source file:edu.clemson.cs.nestbed.server.adaptation.sql.ProjectDeploymentConfigurationSqlAdapter.java
private ProjectDeploymentConfiguration getProjectDeploymentConfiguration(ResultSet resultSet) throws SQLException { int id = resultSet.getInt(Index.ID.index()); int projectID = resultSet.getInt(Index.PROJECTID.index()); String name = resultSet.getString(Index.NAME.index()); String description = resultSet.getString(Index.DESCRIPTION.index()); Date timestamp = resultSet.getDate(Index.TIMESTAMP.index()); return new ProjectDeploymentConfiguration(id, projectID, name, description, timestamp); }
From source file:biblivre3.acquisition.order.BuyOrderDAO.java
private final BuyOrderDTO populateDto(ResultSet rs) throws Exception { final BuyOrderDTO dto = new BuyOrderDTO(); dto.setSerial(rs.getInt("serial_order")); dto.setSerialQuotation(rs.getInt("serial_quotation")); dto.setOrderDate(rs.getDate("order_date")); dto.setResponsible(rs.getString("responsable")); dto.setObs(rs.getString("obs")); dto.setStatus(rs.getString("status")); dto.setInvoiceNumber(rs.getString("invoice_number")); dto.setReceiptDate(rs.getDate("receipt_date")); dto.setTotalValue(rs.getFloat("total_value")); dto.setDeliveredQuantity(rs.getInt("delivered_quantity")); dto.setTermsOfPayment(rs.getString("terms_of_payment")); dto.setDeadlineDate(rs.getDate("deadline_date")); return dto;// www. j a v a 2s.co m }
From source file:com.leapfrog.inventorymanagementsystem.dao.impl.SalesDAOImpl.java
@Override public Sales getById(int id) throws SQLException, ClassNotFoundException { String sql = "SELECT * FROM tbl_sales WHERE sales_id =?"; return jdbcTemplate.queryForObject(sql, new Object[] { id }, new RowMapper<Sales>() { @Override// ww w .j a va 2 s. c o m public Sales mapRow(ResultSet rs, int i) throws SQLException { Sales s = new Sales(); s.setId(rs.getInt("sales_id")); s.setProductId(rs.getInt("product_id")); s.setSellingPrice(rs.getInt("selling_price")); s.setQuantity(rs.getInt("quantity")); s.setDiscount(rs.getBigDecimal("discount")); s.setTotalCost(rs.getInt("total_cost")); s.setSalesDate(rs.getDate("sales_date")); s.setPaymentMethod(rs.getString("payment_method")); s.setStatus(rs.getBoolean("status")); return s; } }); }
From source file:com.jd.survey.dao.survey.QuestionStatisticDAOImp.java
/** * Returns descriptive statistics for numeric date answers (minimum, maximum) * @param question/*from w ww. j a v a2s .com*/ * @return */ private List<QuestionStatistic> getDateDescriptiveStatistics(Question question, final Long totalRecordCount) { Long surveyDefinitionId = question.getPage().getSurveyDefinition().getId(); Short pageOrder = question.getPage().getOrder(); Short questionOrder = question.getOrder(); final String columnName = "p" + pageOrder + "q" + questionOrder; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("select MIN(d." + columnName + ") as min ,MAX(d." + columnName + ") as max "); stringBuilder.append(" from survey_data_" + surveyDefinitionId + " d inner join survey s on (s.id=d.survey_id and s.status='S')"); String selectSQLStatement = stringBuilder.toString(); List<QuestionStatistic> questionStatistics = this.jdbcTemplate.query(selectSQLStatement, new RowMapper<QuestionStatistic>() { public QuestionStatistic mapRow(ResultSet rs, int rowNum) throws SQLException { QuestionStatistic questionStatistic = new QuestionStatistic(); questionStatistic.setMinDate(rs.getDate("min")); questionStatistic.setMaxDate(rs.getDate("max")); questionStatistic.setTotalCount(totalRecordCount); return questionStatistic; } }); return questionStatistics; }
From source file:com.leapfrog.inventorymanagementsystem.dao.impl.SalesDAOImpl.java
@Override public List<Sales> getALL(boolean status) throws SQLException, ClassNotFoundException { String sql = "SELECT * FROM tbl_sales WHERE 1=1"; if (status) { sql += " AND status=1 "; }/*from ww w . j a v a2s . c o m*/ return jdbcTemplate.query(sql, new RowMapper<Sales>() { @Override public Sales mapRow(ResultSet rs, int i) throws SQLException { Sales s = new Sales(); s.setId(rs.getInt("sales_id")); s.setProductId(rs.getInt("product_id")); s.setSellingPrice(rs.getInt("selling_price")); s.setQuantity(rs.getInt("quantity")); s.setDiscount(rs.getBigDecimal("discount")); s.setTotalCost(rs.getInt("total_cost")); s.setSalesDate(rs.getDate("sales_date")); s.setPaymentMethod(rs.getString("payment_method")); s.setStatus(rs.getBoolean("status")); return s; } }); }
From source file:edu.clemson.cs.nestbed.server.adaptation.sql.ProgramMessageSymbolSqlAdapter.java
private final ProgramMessageSymbol getProgramMessageSymbol(ResultSet resultSet) throws SQLException { int id = resultSet.getInt(Index.ID.index()); int programID = resultSet.getInt(Index.PROGRAMID.index()); String name = resultSet.getString(Index.NAME.index()); Blob bytecodeBlob = resultSet.getBlob(Index.BYTECODE.index()); Date timestamp = resultSet.getDate(Index.TIMESTAMP.index()); byte[] bytecode = bytecodeBlob.getBytes(1, (int) bytecodeBlob.length()); return new ProgramMessageSymbol(id, programID, name, bytecode, timestamp); }
From source file:com.ewcms.component.online.dao.WorkingDAO.java
public List<Article> findArticle(int id) { // String sql = "Select url,title,published From plugin_workingbody_articlemain t1,content_article_main t2,content_article t3 " // + "Where t1.articlemain_id = t2.id And t2.article_id = t3.id And t3.status ='RELEASE' And t1.workingbody_id = ? " // + "Order By t3.published"; String sql = "Select url,title,published From " + "plugin_workingbody_articlemain t1 left join content_article_main t2 on t1.articlemain_id=t2.id " + "left join content_article t3 on t2.article_id=t3.id " + "Where t3.status ='RELEASE' And t1.workingbody_id = ? Order By t3.published "; List<Article> articles = jdbcTemplate.query(sql, new Object[] { id }, new RowMapper<Article>() { @Override/*from www . ja va2s. c o m*/ public Article mapRow(ResultSet rs, int rowNum) throws SQLException { Article article = new Article(); article.setUrl(rs.getString("url")); article.setTitle(rs.getString("title")); article.setPublished(rs.getDate("published")); return article; } }); return articles; }
From source file:org.castor.cpa.test.test203.TestTimezone.java
public void testDate() throws Exception { Database db = getJDOManager(DBNAME, MAPPING).getDatabase(); LOG.debug("user.timezone = " + System.getProperty("user.timezone")); AbstractProperties properties = CPAProperties.newInstance(); String testTimezone = properties.getString(CPAProperties.DEFAULT_TIMEZONE, "CET"); LOG.debug(CPAProperties.DEFAULT_TIMEZONE + " = " + testTimezone); /*//from w ww . j a v a 2 s .c om * Create a date object */ String dateString = "1968-09-22 00:00:00 " + testTimezone; Date date = null; try { date = DF.parse(dateString); } catch (ParseException e) { LOG.error("ParseException thrown", e); fail("Unable to parse " + dateString); } Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); date = cal.getTime(); LOG.debug("Original = " + DF.format(date) + "[" + date.getTime() + "]"); /* * Remove old entities from the database */ LOG.debug("Remove old entities"); db.begin(); String sqldel = "DELETE FROM " + TABLE_NAME; Connection connectiondel = db.getJdbcConnection(); Statement statementdel = connectiondel.createStatement(); statementdel.execute(sqldel); db.commit(); /* * Insert new entity into the database */ LOG.debug("Insert new entity"); db.begin(); TimezoneEntity insertEntity = new TimezoneEntity(); insertEntity.setId(new Integer(100)); insertEntity.setName("entity 100"); insertEntity.setStartDate(date); insertEntity.setStartTime(null); insertEntity.setStartTimestamp(null); db.create(insertEntity); db.commit(); Integer id = insertEntity.getId(); /* * Clear the cache to ensure we aren't reading cached data */ LOG.debug("Clearing Castor's cache"); db.begin(); db.getCacheManager().expireCache(); db.commit(); /* * Fetch the object again */ LOG.debug("Fetch entity with id = " + id + " with Castor"); db.begin(); Object fetchEntity = db.load(TimezoneEntity.class, id); Date castorDate = ((TimezoneEntity) fetchEntity).getStartDate(); LOG.debug("Castor = " + DF.format(castorDate) + "[" + castorDate.getTime() + "]"); db.commit(); assertEquals("Castor date differs from original one!", date, castorDate); /* * Fetch using straight SQL and compare the result with our original * date */ LOG.debug("Fetch entity with id = " + id + " with straight SQL"); Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone(testTimezone)); String sql = "SELECT start_date FROM " + TABLE_NAME + " WHERE id = " + id; try { db.begin(); Connection connection = db.getJdbcConnection(); Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery(sql); resultSet.next(); Date localDate = resultSet.getDate(1); LOG.debug("SQL without Calendar " + DF.format(localDate) + " [" + localDate.getTime() + "]"); Date utcDate = resultSet.getDate(1, calendar); LOG.debug("SQL with " + testTimezone + " Calendar " + DF.format(utcDate) + " [" + utcDate.getTime() + "]"); db.commit(); assertEquals("SQL date differs from original one!", date, utcDate); } catch (PersistenceException e) { LOG.error("PersistenceException thrown", e); fail(); } catch (SQLException e) { LOG.error("SQLException thrown", e); fail(); } db.close(); }