无为

无为则可为,无为则至深!

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  190 Posts :: 291 Stories :: 258 Comments :: 0 Trackbacks
当你需要多次执行相同的SQL语句(一般情况下是update)但是使用不同的参数值时 ,可以使用
PrepareStatement方法,举例如下:

Connection conn=null;
PreparedStatement pst=null;
String[] nm=new String[3];
int[] nc=new int[3];
...
try {
nm[0]="Costescu",nm[1]="Alexandrescu",nm[2]="Popovici";
nc[0]=234423;nc[1]=123344;nc[2]=534562;

pst=conn.prepareStatement("UPDATE Table1 SET Nume=? WHERE Nr_cont=?");
for(int i=0;i<=2;i++)
{
pst.setString(1,nm[i]);
pst.setInt(2,nc[i]);
pst.executeUpdate();
}
}catch (SQLException e){System.out.println(e.getMessage());}
...


凡是有该标志的文章,都是该blog博主Caoer(草儿)原创,凡是索引、收藏
、转载请注明来处和原文作者。非常感谢。

posted on 2007-09-05 14:12 草儿 阅读(1392) 评论(0)  编辑  收藏 所属分类: DB编程

只有注册用户登录后才能发表评论。


网站导航: