您的位置:程序门 -> java -> j2ee / ejb / jms



前辈们帮小弟看下为什么取不出来list 元素呢???????????????


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


前辈们帮小弟看下为什么取不出来list 元素呢???????????????
发表于:2007-06-15 10:07:11 楼主
这个是teldaoimple类


//按关键字查找
public   list   serachkey(string   key)   {
//   todo   auto-generated   method   stub
tel   tel=null;
list   list=new   arraylist();
con=dbconnection.getconnection();
try   {
ps=con.preparestatement( "select   *   from   info   where   name=?   or   tel1=?   or   tel2=? ");
ps.setstring(1,   key);
ps.setstring(2,   key);
ps.setstring(3,   key);
rs=ps.EXECutequery();
while(rs.next()){
tel=new   tel();
tel.setname(rs.getstring( "name "));
tel.settype(rs.getstring( "type "));
tel.settel1(rs.getstring( "tel1 "));
tel.settel2(rs.getstring( "tel2 "));
tel.setaddress(rs.getstring( "address "));
tel.setzip(rs.getstring( "zip "));
list.add(tel);
}
}   catch   (sqlexception   e)   {
//   todo   auto-generated   catch   block
e.printstacktrace();
}   finally{
try   {
ps.close();
con.close();
ps=null;
con=null;
}   catch   (sqlexception   e)   {
//   todo   auto-generated   catch   block
e.printstacktrace();
}

}

return   list;
}
  这个是测试类
tel   tel=new   tel();
list   list=(list)dao.serachkey( "王东杰 ");
system.out.println(list.length());
for(int   i=0;i <list.length();i++){
tel=list[i];
}

取不出来我用的是eclipse   ,老说tel=list[i];
这有错

发表于:2007-06-15 10:12:061楼 得分:0
tel   tel=null;
list   list=(list)dao.serachkey( "王东杰 ");
system.out.println(list.size());
for(int   i=0;i <list.size();i++){
tel=(tel)list.get(i);
发表于:2007-06-15 10:13:372楼 得分:0
for(int   i=0;i <list.size();i++)
        tel=(tel)list.get(i);
发表于:2007-06-15 10:16:223楼 得分:0
for(int   i=0;i <list.length();i++){
tel=list[i];
}
==〉
for(int   i=0;i <list.size();i++){
      tel=(tel)list.get(i);
}
发表于:2007-06-15 11:23:404楼 得分:0
集合里没有length();这有size()方法,还有就是没有集合没有list[i],象是c#里的索引似的.要用集合的get方法,而且还要强制转换成bean类的对象
发表于:2007-06-15 11:36:515楼 得分:0
从list中取数据是要用get(i)方法,还有就是取出的数据的类型要和你定义的对象的类型要匹配..
发表于:2007-06-15 13:43:386楼 得分:0
list可不是数组哦

list长度:list.size()
获取第i个列表元素   tel   =   (tel)list.get(i)
发表于:2007-06-17 00:39:597楼 得分:0
你的写法有问题
应该为
iterator   i=list.iterator();
while(i.hasnext())
{
        tel=(tel   )i.next();
}
这个问题不难呀
发表于:2007-06-17 22:43:078楼 得分:0
ls

说的都对

lz还不伞分
发表于:2007-06-18 15:04:179楼 得分:0
list.length()   这种写法好像不对吧!!!

应当将list遍历一下!

tangwei968548()     顶你!!!!
发表于:2007-06-19 12:08:5610楼 得分:0
强制类型转换.   或者你开始用   list的时候就用泛型.
发表于:2007-06-21 16:01:3311楼 得分:0
都对
发表于:2007-06-21 16:09:4612楼 得分:0
全说完了...没机会了
发表于:2007-06-27 16:17:3513楼 得分:0
是啊,那就结   贴吧
发表于:2007-06-27 18:09:2614楼 得分:0
散分好吃饭啊~~~~


快速检索

最新资讯
热门点击