0
点赞
收藏
分享

微信扫一扫

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

weednoah 2022-02-28 阅读 107


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



举报

相关推荐

0 条评论