java批量执行多条Sql语句

/**
* 执行多条更新的Sql语句
*/
public boolean UpdataSql(String sql[]){
TestConnect.Connect();
try {
sta = TestConnect.connection.createStatement();
for(int i=0;i sta.addBatch(sql[i]);
System.out.println("输出SQL语句:"+sql[i]);
}
sta.executeBatch();//执行
return(true);
}
catch (Exception ex) {
System.out.println("Error : " + ex.toString());
return(false);
}
finally{
try{
TestConnect.connection.commit();
sta.close();
TestConnect.connection.close();

}catch(Exception e){
e.printStackTrace();
}
}
}

你可能感兴趣的:(sql语句)