欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2022-06-15 09:11:05
...

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