Topic: Collection ret=new ArrayList();谁能帮帮我如何理解这个码段

  Print this page

1.Collection ret=new ArrayList();谁能帮帮我如何理解这个码段 Copy to clipboard
Posted by: sshgwyx
Posted on: 2004-09-13 10:56

public Collection getMessage()throws Exception
{
Collection ret=new ArrayList();
try
{
Statement stm=con.createStatement();
ResultSet result=stm.executeQuery("select countStart from message");  
 int message_count=0;
 if(result.next())
 {
   message_count=result.getInt(1);
    result.close();      
 }
 if(message_count>0)
 {
  result=stm.executeQuery("select * from message order by time desc");
  while(result.next())
  {       
    String title=result.getString("title");
    MessageVO message=new MessageVO();
    message.setName(name);
    ret.add(message);//??如何理解
        
  }
  result.close();
  stm.close();
  }      
  con.close();
     }
  catch(Exception e)
  {
  e.printStackTrace();
  throw e;
  }
  return ret;//??如何理解
}

2.Re:Collection ret=new ArrayList();谁能帮帮我如何理解这个码段 [Re: sshgwyx] Copy to clipboard
Posted by: zzgf16
Posted on: 2004-09-13 13:19

public Collection getMessage()throws Exception
{
Collection ret=new ArrayList();
try
{
Statement stm=con.createStatement();
ResultSet result=stm.executeQuery("select countStart from message");
 int message_count=0;
 if(result.next())
 {
   message_count=result.getInt(1);//返回message表里的所有记录数
result.close();
 }
 if(message_count>0)
 {
  result=stm.executeQuery("select * from message order by time desc");//如果message表里有记录按时间time的降序排列
while(result.next())
{
String title=result.getString("title");//String title定义错了,应该是name
MessageVO message=new MessageVO();
message.setName(name);
ret.add(message);//??如何理解:ret是ARRAYLIST型集合,它加入了MessageVO 的对象

}
result.close();
stm.close();
}
con.close();
     }
catch(Exception e)
{
e.printStackTrace();
throw e;
}
return ret;//??如何理解//返回ret这个集合,集合里包含着message表里title字段的名字的多个MessageVO对象
}
请大家批评指正,谢谢!!

3.Re:Collection ret=new ArrayList();谁能帮帮我如何理解这个码段 [Re: sshgwyx] Copy to clipboard
Posted by: sshgwyx
Posted on: 2004-09-13 14:42

谢谢了!快乐同您常在


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923