//6. 解析结果集
List<Fruit> fruitList = new ArrayList<>();
while (rs.next()){
int fid = rs.getInt(1);
String fname = rs.getString("fname");
int price = rs.getInt(3);
int fcount = rs.getInt(4);
String remake = rs.getString(5);
Fruit fruit = new Fruit(fid,fname,price,fcount,remake);
fruitList.add(fruit);
}
//7. 释放资源
rs.close();
psmt.close();
conn.close();
fruitList.forEach(System.out::println);
练习jdbc查找方法,最后需要打印list中所有的对象,打印结果为如下地址。
com.ya.jdbc.Fruit@1b7cc17c
com.ya.jdbc.Fruit@59662a0b
com.ya.jdbc.Fruit@77fbd92c
com.ya.jdbc.Fruit@67c27493
崩溃中,自己只是明确的知道当前代码没有问题,于是查找Fruit中的代码
发现少了toString()
........
@Override
public String toString() {
return "Fruit{" +
"fid=" + f