List of usage examples for org.joda.time LocalDate withFieldAdded
public LocalDate withFieldAdded(DurationFieldType fieldType, int amount)
From source file:com.graph.line.LineGraphData.java
public LineGraphData(String timeIn, String timeOut) { java.sql.Connection con = null; java.sql.PreparedStatement stmt = null; java.sql.ResultSet rs = null; try {/*from w w w . ja v a 2 s. co m*/ con = ControlPanelPool.getInstance().getConnection(); DateTimeFormatter format = org.joda.time.format.DateTimeFormat.forPattern("MM/dd/yyyy"); LocalDate startDate = LocalDate.parse(timeIn, format); LocalDate endDate = LocalDate.parse(timeOut, format); int days = Days.daysBetween(startDate, endDate).getDays(); //List<LocalDate> dates = new ArrayList<>(days); sessionCount = new ArrayList<>(); addressCount = new ArrayList<>(); dateCount = new ArrayList<>(); for (int i = 0; i < days; i++) { LocalDate d2 = startDate.withFieldAdded(DurationFieldType.days(), i + 1); //dates.add(d); stmt = con.prepareStatement( "SELECT COUNT(DISTINCT remoteAddress) as remoteAdd, COUNT(DISTINCT sessionId) as sess FROM leadSession WHERE timeIn > CONVERT(date, ?) AND timeIn < CONVERT(date, ?)"); stmt.setString(1, startDate.withFieldAdded(DurationFieldType.days(), i).toString()); stmt.setString(2, startDate.withFieldAdded(DurationFieldType.days(), i + 1).toString()); rs = stmt.executeQuery(); while (rs.next()) { sessionCount.add(rs.getString("sess")); addressCount.add(rs.getString("remoteAdd")); } dateCount.add(startDate.withFieldAdded(DurationFieldType.days(), i).toString()); } con.close(); } catch (IOException | SQLException | PropertyVetoException ex) { Logger.getLogger(LineGraphData.class.getName()).log(Level.SEVERE, null, ex); } finally { DbUtils.closeQuietly(con, stmt, rs); } }