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

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

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


相关文章
|
9月前
|
Java 编译器 数据库连接
Cause java.sql.SQLDataException Unsupported conversion from LONG to java.sql.Timestamp
Cause java.sql.SQLDataException Unsupported conversion from LONG to java.sql.Timestamp
357 0
|
1月前
|
SQL Java 数据库连接
解决bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: ORA-00911: 无效字符
解决bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: ORA-00911: 无效字符
24 0
|
5月前
|
SQL Oracle 关系型数据库
【已解决】nested exception is java.sql.SQLDataException: ORA-01476: divisor is equal to zero
【已解决】nested exception is java.sql.SQLDataException: ORA-01476: divisor is equal to zero
44 1
|
9月前
|
SQL 人工智能 Java
SQLException: Value ‘0000-00-00 00:00:00‘ can not be represented as java.sql.Timestamp
SQLException: Value ‘0000-00-00 00:00:00‘ can not be represented as java.sql.Timestamp
|
10月前
|
Oracle 关系型数据库 数据库
nested exception is java.sql.SQLSyntaxErrorException: ORA-02289: 序列不存在(详细讲解)
nested exception is java.sql.SQLSyntaxErrorException: ORA-02289: 序列不存在(详细讲解)
157 0
|
SQL Java 数据库连接
【异常】Cause: java.sql.SQLException: Invalid value for getInt()
java.sql.SQLException: Invalid value for getInt()
270 1
java.sql.SQLException: sql injection violation
本文目录 1. 报错信息 2. 问题分析 3. 排除法 4. 解决方案
2034 0
|
SQL Java 关系型数据库
java执行自定义sql时报错 error in your SQL syntax;
java执行自定义sql时报错 error in your SQL syntax;
149 0
java执行自定义sql时报错 error in your SQL syntax;
使用QueryRunner报错:java.sql.SQLException: Cannot create
使用QueryRunner报错:java.sql.SQLException: Cannot create
153 0