毕业论文开发语言企业开发JAVA技术.NET技术WEB开发Linux/Unix数据库技术Windows平台移动平台嵌入式论文范文英语论文
您现在的位置: 毕业论文 >> java技术 >> 正文

批处理代码可以将PreparedStatement对象反复利用吗

更新时间:2012-8-2:  来源:毕业论文

String sq1="select * from HrEmployee where cardid in("+sa+")";
String sq2="select * from EquFinger where cardid in("+sa+")";
String sq3="select * from EquCard where cardid in("+sa+")";

String st1[][]=msql.executeQuery(sq1,strDB1);
String st2[][]=msql.executeQuery(sq2,strDB1);
String st3[][]=msql.executeQuery(sq3,strDB1);
                       
                       
                       
String sqla0="insert into  HrEmployee(EmplID,WorkID,CardID,DeptID,EmplName,Sex,EntryDate,LeaveYN,LastOperId,LastOperDate ) values (?,?,?,?,?,?,?,?,?,?)";

String sqla1="insert into  EquFinger (EmplID,CardNo,BackupID,Privilege,pws  ) values (?,?,?,?,?)";
                       
String sqla2="insert into  EquCard (CardNo,EmplID,CardType,CardStatus ) values (?,?,?,?)";
                       
PreparedStatement psStatementin=msql.executeUpdate(sqla0,strDB2);
                       
                        for(int i=0;i<st1.length;i++)
                        {
                           
                            psStatementin.setString(1,st1[i][0]);
                            psStatementin.setString(2,st1[i][1]);
                            psStatementin.setString(3,st1[i][2]);
                            psStatementin.setString(4,st1[i][3]);
                            psStatementin.setString(5,st1[i][4]);
                            psStatementin.setString(6,st1[i][5]);
                            psStatementin.setString(7,st1[i][6]);
                            psStatementin.setString(8,st1[i][7]);
                            psStatementin.setString(9,st1[i][8]);
                            psStatementin.setString(10,st1[i][9]);
                       
                                psStatementin.addBatch();
                        }
                                psStatementin.executeBatch();
                                msql.close();
                               
PreparedStatement psStatementin1=msql.executeUpdate(sqla1,strDB2);
                               
                        for(int i=0;i<st2.length;i++)
                        {
                                   
                            psStatementin1.setString(1,st2[i][0]);
                            psStatementin1.setString(2,st2[i][1]);
                            psStatementin1.setString(3,st2[i][2]);
                            psStatementin1.setString(4,st2[i][3]);
                            psStatementin1.setString(5,st2[i][4]);
                               
                                        psStatementin1.addBatch();
                        }
                                        psStatementin1.executeBatch();
                        msql.close();
       
                       
        PreparedStatement psStatementin2=msql.executeUpdate(sqla2,strDB2);
                                       
            for(int i=0;i<st3.length;i++)
        {
                                           
                                            psStatementin2.setString(1,st3[i][0]);
                                            psStatementin2.setString(2,st3[i][1]);
                                            psStatementin2.setString(3,st3[i][2]);
                                            psStatementin2.setString(4,st3[i][3]);                                       
                                                psStatementin2.addBatch();
}
                                                psStatementin2.executeBatch();
                                                msql.close();  
排版有点乱,两个疑问,一个希望
1.那个close是关闭数据库连接的,核心代码,就是Connection 对象调用close()方法,我想问的是,用的着这样,关闭3次吗?
2.三次批处理,用了3个PreparedStatement对象,我想问,可以将这个对象反复使用吗?使用把它初始化成什么比较合理。

[1] [2] 下一页

设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©youerw.com 优尔论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。