日期:2014-05-20  浏览次数:20720 次

SQL语句打印出来怎是这样啊,求解
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吧怎会这样我已转换成字符窜了啊
不懂。。。。请各位大哥们指点   在此感激

------解决方案--------------------
用迭代器遍历Iterator
------解决方案--------------------
bookId=ay.get(i).toString();

改成:
bookId=((BookBean)(ay.get(i))).getBookId();
------解决方案--------------------
bookId=String.valueOf(ay.get(i))
------解决方案--------------------
rs.getString(2)
你的数据库里是正确的值吗?
------解决方案--------------------
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]
------解决方案--------------------
你第二次取到的bookId是地址。
你可以先用DEBUG的方式,看一下,所传入的参数是些什么值。我觉得是你传入参数有问题。
我试过,ArrayList可以用LZ的方法。
还有楼上用的那个SQL:str = "select * from bookView where bookId = "+ " ' "+bookId+ " ' "
不要这么麻烦:可以用str = "select * from bookView where bookId = ' "bookId+ " ' ";