public boolean duofa(String ad[]){
boolean resave=false;
try{
stat=conn.createStatement();
for(int i=0;i<ad.length;i++){
sql = "update Supply_data set time='" + sqltime +
"' where id='"+ad[i]+"'";
if(stat.executeUpdate(sql)>0){
resave=false;
}
}
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
try{
stat.close();
if (conn != null && !conn.isClosed()) { conn.close(); }
}catch(Exception e){}
}
return resave;
}
public boolean duofa(String ad[]){
boolean resave=false;
try{
for(int i=0;i<ad.length;i++){
stat=conn.createStatement();
sql = "update Supply_data set time='" + sqltime +
"' where id='"+ad[i]+"'";
if(stat.executeUpdate(sql)>0){
resave=false;
}
stat.close();
}
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
try{
stat.close();
if (conn != null && !conn.isClosed()) { conn.close(); }
}catch(Exception e){}
}
return resave;
}
上边哪个共好,从内存和速度上哪个更好?
boolean resave=false;
try{
stat=conn.createStatement();
for(int i=0;i<ad.length;i++){
sql = "update Supply_data set time='" + sqltime +
"' where id='"+ad[i]+"'";
if(stat.executeUpdate(sql)>0){
resave=false;
}
}
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
try{
stat.close();
if (conn != null && !conn.isClosed()) { conn.close(); }
}catch(Exception e){}
}
return resave;
}
public boolean duofa(String ad[]){
boolean resave=false;
try{
for(int i=0;i<ad.length;i++){
stat=conn.createStatement();
sql = "update Supply_data set time='" + sqltime +
"' where id='"+ad[i]+"'";
if(stat.executeUpdate(sql)>0){
resave=false;
}
stat.close();
}
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
try{
stat.close();
if (conn != null && !conn.isClosed()) { conn.close(); }
}catch(Exception e){}
}
return resave;
}
上边哪个共好,从内存和速度上哪个更好?
解决方案 »
- 看了servlet源码有一些疑问不明,望高手指点。
- java解析xml时如何获得一个节点下相同叶子节点的值
- 大神求救
- 使用ServletContextListener用两个while循环加一个hashmap每天早上都要重启服务程序才能正常运行?
- 急求解决方案 description The server encountered an internal error () that prevented it from fulfilling this request.
- ssh整合
- 为什么我登陆完论坛发完帖子或问完问题马上就变成游客了??!!
- 用户在文本框里输入"%20",提交后收到的却是空格,怎么才能够收到"%20"呢???
- 怎么样配置Tomcat4.1.18+Jdk1.4,在线等待...
- 连结数据库出错!
- hibernate 查询结果为null oracle
- 急急急!在线等,特殊字符(Ø)在JSP页面怎么处理
第一个stat只建立了一个
第二个建立了ad.length - 1个
boolean resave=false;
try{
stat=conn.createStatement();
String sql = "update Supply_data set time='" + sqltime + "' where id in (";
String whereid="";
for(int i=0;i <ad.length;i++){
String id="'"+ad[i]+"'";
whereid+=id;
}
whereid+=")"
sql+=whereid;
if(stat.executeUpdate(sql)>0){
resave=false;
}
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
try{
stat.close();
if (conn != null && !conn.isClosed()) { conn.close(); }
}catch(Exception e){}
}
return resave;
}
前提是方法的参数String ad[]长度不为0;