有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在netbeans中计算从数据库检索到的数据

我很抱歉,这听起来可能是一个非常糟糕的问题,但我尽了很大努力来完成这项工作。我需要检索已经存储在数据库中的数据,进行计算,并将结果存储回表中。这是我写的代码我的问题是数据没有存储在数据库中。我不懂编码,所以请帮帮我

try{

        String sql="Select * from Allowance order by Employee_No,Year,Month ASC";
        pst=conn.prepareStatement(sql);
        rs=pst.executeQuery();


        do {
            String PreEmpNo=rs.getString("Employee_No");
            int Amt=0;
            String code=rs.getString("Item_Code");
            do {
                Amt=Amt+rs.getInt("Amount");

            }while(rs.next() && (PreEmpNo.equals(rs.getString("Employee_No"))) && (code.equals(rs.getString("Item_Code"))));
            if(Amt>0){

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


                bar.setValue(15);

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

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

共 (0) 个答案