Example usage for java.sql ResultSet getDate

List of usage examples for java.sql ResultSet getDate

Introduction

In this page you can find the example usage for java.sql ResultSet getDate.

Prototype

java.sql.Date getDate(String columnLabel) throws SQLException;

Source Link

Document

Retrieves the value of the designated column in the current row of this ResultSet object as a java.sql.Date object in the Java programming language.

Usage

From source file:DataCharts.Chart.java

/**
 * Creates a dataset, consisting customers per area code
 * Methods are for display purposes at this point and may be refactored and 
 * modified based on necessity/*from  ww  w  .j  a v  a  2 s  . co  m*/
 */
private XYDataset createXYDataset(ArrayList<YearData> locs) {

    try {
        ResultSet locations = db.selectDataColumn("customer", "*");
        TimeSeriesCollection dataset = new TimeSeriesCollection();

        Calendar defCal = Calendar.getInstance();
        defCal.set(2015, 1, 1);
        int defMonthNum = defCal.get(Calendar.MONTH);
        TimeSeries defTime = new TimeSeries("" + defCal.get(Calendar.MONTH));
        Month defMonth = new Month(defMonthNum, 2015);
        defTime.addOrUpdate(defMonth, 0);

        defCal = Calendar.getInstance();
        defCal.set(2015, 6, 6);
        defMonthNum = defCal.get(Calendar.MONTH);
        defTime = new TimeSeries("" + defCal.get(Calendar.MONTH));
        defMonth = new Month(defMonthNum, 2015);
        defTime.addOrUpdate(defMonth, 0);

        dataset.addSeries(defTime);
        while (locations.next()) {

            ResultSet jobDates = db.selectDataColumn("jobs", "date", locations.getString(2), "CustomerID");
            TimeSeries time = new TimeSeries("" + locations.getInt(7));
            int n = 0;
            Month month = null;
            while (jobDates.next()) {
                if (n == 0) {
                    Calendar cal = Calendar.getInstance();
                    cal.setTime(jobDates.getDate(1));
                    int monthNum = cal.get(Calendar.MONTH);
                    month = new Month(monthNum, 2015);
                }
                n++;

            }
            if (month != null) {
                time.addOrUpdate(month, n);
                dataset.addSeries(time);
            }
        }
        return dataset;
    } catch (SQLException ex) {
        Logger.getLogger(Chart.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}

From source file:edu.clemson.cs.nestbed.server.adaptation.sql.MoteDeploymentConfigurationSqlAdapter.java

private final MoteDeploymentConfiguration getMoteDeploymentConfiguration(ResultSet resultSet)
        throws SQLException {
    int id = resultSet.getInt(Index.ID.index());
    int configID = resultSet.getInt(Index.PROJECTCONFID.index());
    int moteID = resultSet.getInt(Index.MOTEID.index());
    int programID = resultSet.getInt(Index.PROGRAMID.index());
    int radioPowerLevel = resultSet.getInt(Index.RADIOPOWERLEVEL.index());
    Date timestamp = resultSet.getDate(Index.TIMESTAMP.index());

    return new MoteDeploymentConfiguration(id, configID, moteID, programID, radioPowerLevel, timestamp);
}

From source file:nl.tudelft.stocktrader.derby.DerbyOrderDAO.java

public Holding getHolding(int holdingId) throws DAOException {
    Holding holding = null;/*from   w  w  w.j  a  v  a  2 s  .  c o  m*/
    PreparedStatement selectHoldingStat = null;
    try {
        selectHoldingStat = sqlConnection.prepareStatement(SQL_SELECT_HOLDING);
        selectHoldingStat.setInt(1, holdingId);
        ResultSet rs = selectHoldingStat.executeQuery();
        if (rs.next()) {
            try {
                holding = new Holding(rs.getInt(1), rs.getDouble(2), rs.getBigDecimal(3),
                        StockTraderUtility.convertToCalendar(rs.getDate(4)), rs.getString(5), rs.getInt(6));
                return holding;

            } finally {
                try {
                    rs.close();
                } catch (Exception e) {
                    logger.debug("", e);
                }
            }
        }
    } catch (SQLException e) {
        throw new DAOException("An Exception is thrown during selecting a holding entry", e);
    } finally {
        if (selectHoldingStat != null) {
            try {
                selectHoldingStat.close();
            } catch (SQLException e) {
                logger.debug("", e);
            }
        }
    }
    return holding;
}

From source file:Controllers.AppointmentController.java

/**
 * return list on all appointments.//from   w  w w  .  ja  va  2s .c om
 *
 * @return
 */
public Appointment[] fetchAppointments() {

    Appointment[] appointments = null;

    try {
        Context ctx = new InitialContext();
        DataSource ds = (DataSource) ctx.lookup("jdbc/medicalCareDataSource");
        connection = ds.getConnection();

        Statement stmt = connection.createStatement();

        String smtquery = "SELECT * FROM appointments";
        ResultSet resultSet;
        resultSet = stmt.executeQuery(smtquery);

        List<Appointment> appointmentsList = new ArrayList<Appointment>();
        while (resultSet.next()) {
            Appointment appointment = new Appointment();
            appointment.setAccountId(resultSet.getInt("accountId"));
            appointment.setAppointmentId(resultSet.getInt("appointmentId"));
            appointment.setDate(resultSet.getDate("date"));
            appointment.setDepartmentId(resultSet.getInt("departmentId"));
            appointment.setMessage(resultSet.getString("message"));
            appointmentsList.add(appointment);
        }

        appointments = new Appointment[appointmentsList.size()];
        appointments = appointmentsList.toArray(appointments);

        stmt.close();

    } catch (NamingException ex) {
        Logger.getLogger(AppointmentController.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SQLException ex) {
        Logger.getLogger(AppointmentController.class.getName()).log(Level.SEVERE, null, ex);
    }

    return appointments;
}

From source file:com.leapfrog.inventorymanagementsystem.dao.impl.ProductDAOImpl.java

@Override
public Product getById(int id) throws SQLException, ClassNotFoundException {
    String sql = "SELECT * FROM tbl_product WHERE product_id =?";
    return jdbcTemplate.queryForObject(sql, new Object[] { id }, new RowMapper<Product>() {

        @Override//from ww w . j  a va 2 s.c  o  m
        public Product mapRow(ResultSet rs, int i) throws SQLException {
            Product p = new Product();
            p.setId(rs.getInt("product_id"));
            p.setProductName(rs.getString("product_name"));
            p.setCostPrice(rs.getInt("cost_price"));
            p.setSellingPrice(rs.getInt("selling_price"));
            p.setDiscount(rs.getBigDecimal("discount"));
            p.setQuantity(rs.getInt("quantity"));
            p.setCategoryName(rs.getString("category_name"));
            p.setSupplierId(rs.getInt("supplier_id"));
            p.setAddedDate(rs.getDate("added_date"));
            p.setModifiedDate(rs.getDate("modified_date"));
            p.setStatus(rs.getBoolean("status"));
            return p;
        }
    });
}

From source file:com.leapfrog.inventorymanagementsystem.dao.impl.ProductDAOImpl.java

@Override
public List<Product> getALL(boolean inStock) throws SQLException, ClassNotFoundException {
    String sql = "SELECT * FROM tbl_product WHERE 1=1";

    if (inStock) {
        sql += " AND status=1 ";
    }/*from  w ww.  j ava 2s .c  om*/
    return jdbcTemplate.query(sql, new RowMapper<Product>() {

        @Override
        public Product mapRow(ResultSet rs, int i) throws SQLException {
            Product p = new Product();
            p.setId(rs.getInt("product_id"));
            p.setProductName(rs.getString("product_name"));
            p.setCostPrice(rs.getInt("cost_price"));
            p.setSellingPrice(rs.getInt("selling_price"));
            p.setDiscount(rs.getBigDecimal("discount"));
            p.setQuantity(rs.getInt("quantity"));
            p.setCategoryName(rs.getString("category_name"));
            p.setSupplierId(rs.getInt("supplier_id"));
            p.setAddedDate(rs.getDate("added_date"));
            p.setModifiedDate(rs.getDate("modified_date"));
            p.setStatus(rs.getBoolean("status"));

            return p;
        }
    });
}

From source file:netflow.DatabaseProxy.java

private List<AggregationRecord> getAggregationResults() throws SQLException {
    log.debug("getAggregationResults(): <<<");
    List<Integer> clients = getNetworkedClients();
    String collect = getQuery("aggregation.results.get");

    PreparedStatement ps = con.prepareStatement(collect);

    List<AggregationRecord> results = new ArrayList<AggregationRecord>();
    for (Integer id : clients) {
        ps.setInt(1, id);/*from   ww w .j  a  va 2s  . co  m*/
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            results.add(new AggregationRecord(rs.getInt(1), rs.getDate(2), rs.getLong(3), rs.getLong(4)));
        }
        rs.close();
    }
    ps.close();
    log.debug("getAggregationResults(): >>>");
    return results;
}

From source file:netflow.DatabaseProxy.java

private List<AggregationRecord> getAggregationResults(Date date) throws SQLException {
    if (date == null) {
        return getAggregationResults();
    }/*  www . j a v  a  2  s .c  o  m*/
    log.debug("getAggregationResults(date): <<<");
    log.debug("Getting user list");

    Timestamp start = Utils.getStartDate(date);
    Timestamp end = Utils.getEndDate(date);
    log.debug("Parameters: " + start + ", " + end);

    List<Integer> clients = getNetworkedClients();
    String collect = getQuery("aggregations.forday.get");
    PreparedStatement ps = con.prepareStatement(collect);

    final List<AggregationRecord> results = new ArrayList<AggregationRecord>();
    for (Integer id : clients) {
        ps.setTimestamp(1, start);
        ps.setTimestamp(2, end);
        ps.setInt(3, id);
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            results.add(new AggregationRecord(rs.getInt(1), rs.getDate(2), rs.getLong(3), rs.getLong(4)));
        }
        rs.close();
    }
    ps.close();
    log.debug("getAggregationResults(): >>>");
    return results;
}

From source file:AuctionServlet.java

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        PreparedStatement stmt = null;

        try {/* w ww.jav  a  2s . c  o  m*/

            Class.forName("org.postgresql.Driver");
            URI dbUri = new URI(
                    "postgres://mvraljhmxcpilo:bKYSixo3rO1Z0cxAmyqMMcK7PG@ec2-75-101-162-243.compute-1.amazonaws.com:5432/d89kgd9u0h1bk3?username=mvraljhmxcpilo&password=bKYSixo3rO1Z0cxAmyqMMcK7PG&ssl.true&sslfactory=org.postgresql.ssl.NonValidatingFactory");

            String username = dbUri.getUserInfo().split(":")[0];
            String password = dbUri.getUserInfo().split(":")[1];
            String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + ':' + dbUri.getPort() + dbUri.getPath();

            this.conn = DriverManager.getConnection(dbUrl, username, password);
            String sql;
            sql = "Select * \n" + " from BidData inner join CustomerData on \n"
                    + "BidData.CustomerID=CustomerData.CustomerID inner join \n"
                    + "ProductData on ProductData.ProductID=BidData.ProductID;";
            stmt = conn.prepareStatement(sql);
            ResultSet rs;
            rs = stmt.executeQuery(sql);
            JSONObject dataobj = new JSONObject();
            while (rs.next()) {
                dataobj.put("ProductID", rs.getInt("ProductID"));
                dataobj.put("ProductName", rs.getString("ProductName"));
                dataobj.put("SellerPrice", rs.getInt("SellerPrice"));
                dataobj.put("TimeLimit", rs.getInt("TimeLimit"));
                dataobj.put("ItemCondition", rs.getString("ItemCondition"));
                dataobj.put("DateSubmitted", rs.getDate("DateSubmitted"));
                dataobj.put("ProductPrice", rs.getInt("ProductPrice"));

            }
            out.println(dataobj);
            rs.close();
            stmt.close();
            conn.close();
        } catch (Exception E) {
            out.println(E.getMessage());
        }

    }
}

From source file:com.jd.survey.dao.survey.QuestionStatisticDAOImp.java

/**
 * Returns descriptive statistics for numeric matrix question' answers (minimum, maximum, average, standard deviation)
 * @param question/*from   w  w w . j  a  va 2s.  c  o m*/
 * @return
 */
private List<QuestionStatistic> getDateMatrixDescriptiveStatistics(Question question,
        final Long totalRecordCount) {
    List<QuestionStatistic> questionStatistics = new ArrayList<QuestionStatistic>();
    Long surveyDefinitionId = question.getPage().getSurveyDefinition().getId();
    Short pageOrder = question.getPage().getOrder();
    Short questionOrder = question.getOrder();

    for (QuestionRowLabel row : question.getRowLabels()) {
        for (QuestionColumnLabel column : question.getColumnLabels()) {
            final Short columnOrder = column.getOrder();
            final Short rowOrder = row.getOrder();
            final String columnName = "p" + pageOrder + "q" + questionOrder + "r" + rowOrder + "c"
                    + columnOrder;
            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> questionCellStatistics = this.jdbcTemplate.query(selectSQLStatement,
                    new RowMapper<QuestionStatistic>() {
                        public QuestionStatistic mapRow(ResultSet rs, int rowNum) throws SQLException {
                            QuestionStatistic questionStatistic = new QuestionStatistic();
                            questionStatistic.setColumnOrder(columnOrder);
                            questionStatistic.setRowOrder(rowOrder);
                            questionStatistic.setMinDate(rs.getDate("min"));
                            questionStatistic.setMaxDate(rs.getDate("max"));
                            questionStatistic.setTotalCount(totalRecordCount);
                            return questionStatistic;
                        }
                    });
            questionStatistics.addAll(questionCellStatistics);
        } //loop on columns
    } //loop on rows
    return questionStatistics;
}