在使用QueryRunner转换查询结果的时候:
QueryRunner qr = new QueryRunner(); List<Book> list = qr.query(sql, new BeanListHandler<Book>(Book.class));
报错
java.sql.SQLException: Cannot create Book
原因
没给Book类写无参构造函数
,加上之后就好了
创建的完整Book类
public class Book { private int bid; private String bname; private float price; private int category; public Book() { } public int getBid() { return bid; } public void setBid(int bid) { this.bid = bid; } public String getBname() { return bname; } public void setBname(String bname) { this.bname = bname; } public float getPrice() { return price; } public void setPrice(float price) { this.price = price; } public int getCategory() { return category; } public void setCategory(int category) { this.category = category; } }