随笔 - 4  文章 - 10  trackbacks - 0
<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

常用链接

留言簿(1)

随笔档案

文章分类

文章档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜

原文出处:http://www.blogjava.net/mlh123caoer/archive/2007/09/05/142885.html
当你需要多次执行相同的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());}
...
posted on 2007-09-05 16:19 冬天出走的猪 阅读(206) 评论(0)  编辑  收藏 所属分类: Database

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


网站导航: