循环后,executeUpdate不起作用

时间:2018-02-18 08:05:15

标签: java sql

我正在尝试将数据从数据库复制到另一个,所以我有下面的代码,循环内部的插入是完美的但是第二次插入不起作用并且没有错误

            Statement st = con.createStatement();
            rs=st.executeQuery("select id,cardid,a2,a2b,a2c,a2e,a17,a11,a16,a15,a14,a20a from a");
            while (rs.next()){
                a=rs.getString(1);
                b=rs.getString(2);
                c=rs.getString(3);
                d=rs.getString(4);
                e=rs.getString(5);
                f=rs.getString(6); 
                g=rs.getString(7); 
                h=rs.getString(8);
                i=rs.getString(9);
                j=rs.getString(10);
                k=rs.getString(11);
                l=rs.getString(12);
                //sql="insert into rpttbl (empid) values ("+a+");";
                sql="insert into rpttbl (temp,empid,name,fname,gname,sname,jkind,jstatus,emplevel,emptitle"
                        + ",cert,pay,pos,except,cens,cuts,med,job,presd,outjob,other,iban) values ("+a+","+"\""+b+"\""+","+"\""+c+""
                        + "\""+","+"\""+d+"\""+","+"\""+e+"\""+","+"\""+f+"\""+","+"\""+g+"\""+","+"\""+h+"\""+","+"\""+i+"\""+""
                        + ","+"\""+j+"\""+","+"'visacard'"+","+"\""+k+"\""+","+"\""+l+"\""+","+"0"+","+"0"+","+"0"+","+"0"+""
                        + ","+"0"+","+0+","+0+","+"0"+","+"0"+");";
                rptStmt= conCreate.prepareStatement(sql);
                rptStmt.executeUpdate(sql);
                //System.out.println("cccccc");
            }


            sql="insert into rpttbl (tax) values (111)";
            rptStmt= conCreate.prepareStatement(sql);
            rptStmt.executeUpdate(sql);

            }

编辑:我注意到只有表格的最后一行有tax = 111

1 个答案:

答案 0 :(得分:0)

问题解决了! 我使用(更新)而不是(插入)