javase写桌面执行程序:前台界面有3个文本输入窗口让客户输入,分别是1.日期,2.天数,3.周期.当用户输入相关的信息后,后台根据(1.日期(首先减一天))减去(2.天数)得到一个(新的日期),然后根据这两个日期放入sql语句中进行查询统计。(3.周期)是循环次数,第2次循环是在上一次(新的日期)减1天后再开始下一次循环。循环结束后把所有循环查出的结果在JTable里打出来。希望有人能解决
package com.test;
import javax.swing.*;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
//import com.test.*;
import com.exceldownload.*;
import com.em.*;
import com.login.*;
import com.login2011.*;
import com.tool.*;
//import com.db.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.text.Format;
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class em_report extends JFrame implements ActionListener {
JPanel jp2;
JLabel jl4, jl5, jl6, jl7;
JScrollPane jsp;
JButton jb5, jb6, jb7, jb8;
JTable jt1;
JTextField date_textfield, days_textfield, period_textfield;
em_dprizhi_model sm;
String sql1 = "select a.r_dpshijian as 日期,(sum(a.r_nanren)+sum(a.r_nvren)+sum(a.r_xiaohai))"
+ " as 进店总人数 from em_dprizhi as a where 1=?";
public static void main(String[] args) {
em_report ip = new em_report();
}
public em_report() {
jp2 = new JPanel();
jb5 = new JButton("返回");
jb5.addActionListener(this);
jb7 = new JButton("倒退日期查询");
jb7.addActionListener(this);
jl4 = new JLabel("起始日期");
jl4.setFont(tools.f);
jl5 = new JLabel("天数");
jl5.setFont(tools.f);
date_textfield = new JTextField(15);
date_textfield.setFont(tools.f);
days_textfield = new JTextField(5);
days_textfield.setFont(tools.f);
jl6 = new JLabel("日期格式(例:2011-06-03)");
jl6.setFont(tools.f);
jb8 = new JButton("生成EXCEL");
jb8.setFont(tools.f);
jb8.addActionListener(this);
jl7 = new JLabel("周期");
jl7.setFont(tools.f);
period_textfield = new JTextField(5);
period_textfield.setFont(tools.f);
jp2.add(jl7);
jp2.add(period_textfield);
jp2.add(jb8);
jp2.add(jl6);
jp2.add(jl4);
jp2.add(date_textfield);
jp2.add(jl5);
jp2.add(days_textfield);
jp2.add(jb7);
jp2.add(jb5);
sm = new em_dprizhi_model();
String[] paras = { "1" };
sm.queryimage(sql1, paras);
jt1 = new JTable(sm);
jsp = new JScrollPane(jt1);
this.add(jsp);
this.add(jp2, "South");
this.setTitle("睿美(EM)业务报表统计");
this.setVisible(true);
this.setSize(1000, 600);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
Date toDate;
Date fromDate;
SimpleDateFormat sdf;
DB db;
PreparedStatement pstmt;
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if (e.getSource() == jb5) {
this.dispose();
//new Windows();
} else if (e.getSource() == jb7) {
// period_textfield---周期/date_textfield--日期/days_textfield--天数
try {
db=new DB();
Connection conn=db.getConn();
String date = this.date_textfield.getText().trim();
String days = this.days_textfield.getText().trim();
String period=this.period_textfield.getText().trim();
sdf=new SimpleDateFormat("yyyy-MM-dd");
toDate = sdf.parse(date);
Calendar calendar = Calendar.getInstance();
calendar.setTime(toDate);
calendar.add(Calendar.DATE, -1*Integer.valueOf(days));