日期:2014-05-20 浏览次数:20698 次
String date = date_textfield.getText(); String days = days_textfield.getText(); String period = period_textfield.getText(); SimplieDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date toDate = sdf.parse(date); Calendar calendar = Calendar.getInstance(); calendar.setTime(toDate); calendar.add(Calendar.DATE, -1*Integer.valueOf(days)); Date fromDate = calendar.getTime(); List<Object[]> view = new ArrayList<Object[]>(); for (int i=0; i<Integer.valueOf(period); i++) { String sql = "select * from your_table where field between ? and ?"; PreparedStatement ps = your_connection.prepareStatement(sql); ps.setDate(1, fromDate); ps.setDate(2, toDate); ResultSet rs = ps.executeQuery(); while (rs.next()) { List<Object> row = new ArrayList<Object>(); for (int i=0; i<rs.getMetaData().getColumnCount()) { row.add(rs.getObject(i)); } view.add(row); } calendar.add(Calendar.DATE, -1); fromDate = calendar.getTime(); } for (int i=0; i<view.size(); i++) { for (int j=0; j<view.get(i).length; j++) { your_jtable.setValueAt(view.get(i)[j], i, j); } }