0

我正在编写一个程序,我需要对数据库中的表进行排序并进行以下计算。但是我没有得到整个表的结果。我只得到表第一行的结果。有人能告诉我吗我怎么了。我的 while 循环正确吗?我应该怎么做才能得到整个表的计算?

    Calendar cal=new GregorianCalendar();
    int c_month=cal.get(Calendar.MONTH);
    int c_year=cal.get(Calendar.YEAR);
    JOptionPane.showMessageDialog(null,"Are You sure You Want to Start Process?");



    try{

    String sql="Select * from Allowance order by Employee_No,Year,Month DESC";
    int i=0;
    pst=conn.prepareStatement(sql);
    bar.setValue(i+5);
    rs=pst.executeQuery();


    do {
        String PreEmpNo=rs.getString("Employee_No");
        int Amt=0;

        do {
            Amt=Amt+rs.getInt("Amount");

            i=i+2;
            bar.setValue(i);
        }while(rs.next() && (PreEmpNo==rs.getString("Employee_No")));
        if(Amt>0){

            String sql1="insert into Payroll values ("+PreEmpNo+","+Amt+")";
            pst = conn.prepareStatement(sql1);
            pst.execute();

           JOptionPane.showMessageDialog(null,"one data saved");
            bar.setValue(i+5);


        }

        }while(rs.next()&& (c_year==rs.getInt("Year")) && (c_month==rs.getInt("Month")));

    }catch(SQLException | HeadlessException e){
        JOptionPane.showMessageDialog(null, e);
    }
4

0 回答 0