使用QueryRunner报错:java.sql.SQLException: Cannot create

半城伤御伤魂 提交于 2020-02-21 22:51:15

在使用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;
    }
}

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!