原文出處:http://m.tkk7.com/mlh123caoer/archive/2007/09/05/142885.html
當(dāng)你需要多次執(zhí)行相同的SQL語(yǔ)句(一般情況下是update)但是使用不同的參數(shù)值時(shí) ,可以使用
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
冬天出走的豬 閱讀(215)
評(píng)論(0) 編輯 收藏 所屬分類:
Database