public ArrayList showCar(ArrayList ay)
{String bookId=null;
String str=null;
for(int i=0;i<ay.size();i++)
{
bookId=ay.get(i).toString();
str="select * from bookView where bookId="+bookId;
System.out.println(str);
                 
try 
{
rs=stmt.executeQuery(str);rs.next())BookBean book=new BookBean();book.setBookId(rs.getString(1));
book.setISBN(rs.getString(2));
book.setBookName(rs.getString(3));
book.setAuthor(rs.getString(4));
book.setPublisher(rs.getString(5));
book.setContent(rs.getString(6));
book.setPrice(rs.getFloat(7));  
book.setTypeId(rs.getString(8));
book.setCount(rs.getInt(9));ay.add(book);
System.out.println(rs.getString(2));}
catch (SQLException e) 
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return ay;
}打印出来怎摸是这样的
select * from bookView where bookId=1
select * from bookView where bookId=book.bean.BookBean@115a298
打印一句怎冒出两句,报SQLException 这个book.bean.BookBean@115a298好象是
hashcode吧怎会这样我已转换成字符窜了啊
不懂。请各位大哥们指点 在此感激

解决方案 »

  1.   

    bookId=ay.get(i).toString();改成:
    bookId=((BookBean)(ay.get(i))).getBookId();
      

  2.   

    先谢谢楼上两位
    我改过后出现了新的异常ClassCastException
    指向的还是这句bookId=((BookBean)(ay.get(i))).getBookId();
    迭代器我试过了也是一样
      

  3.   

    rs.getString(2)
    你的数据库里是正确的值吗?
      

  4.   

    1、str="select * from bookView where bookId="+bookId;
    你这样写得到的sql语句根本就不能被执行!
    改成    str = "select * from bookView where bookId ="+"'"+bookId+"'"2.rs.next()) 这什么意思?是不是写错了?3、book.setBookId(rs.getString(1)); 你的get 方法中1是参数吗?是不是应该是数组的index,
    如:getString[1]
      

  5.   

    String.valueOf(ay.get(i))和toString()的结果都是最初的那样
    rs.getString(2)取出来的是数据库里的记录还是不行啊
    我以前在jsp页面里写也就是用一个循环遍历取出来ay.get(i).toString()加在查询语句后
    都没什么问题,现在怎折磨多啊
      

  6.   

    你第二次取到的bookId是地址。
    你可以先用DEBUG的方式,看一下,所传入的参数是些什么值。我觉得是你传入参数有问题。
    我试过,ArrayList可以用LZ的方法。
    还有楼上用的那个SQL:str = "select * from bookView where bookId ="+"'"+bookId+"'"
    不要这么麻烦:可以用str = "select * from bookView where bookId ='"bookId+"'";