| 发表于: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]; 这有错 |
|
|
|
|