首页 >> 大全

使用dbutils时出现cannot create xxx query情况解决

2024-01-11 大全 17 作者:考证青年

项目场景:

关于使用 数据库 连接池使用查询语句出现的错误

问题描述:

当写好测试类时准备测试查询时出现了这个错误,

java.sql.SQLException: Cannot create com.ishop.pojo.Goods: com.ishop.pojo.Goods Query: select `id`,`sname`,`information`, `brand`, `img_path`, `sales`, `stock` from t_goods where `id` = ? Parameters: [4]

然后在语句在mysql中能正常运行,说明sql语句没有错误

在dao中写好测试类准备测试,发现出现了如上错误

实体类如下

public class Goods {private Integer id;          //商品编号private String sname;        //商品名public Goods(Integer id, String sname) {this.id = id;this.sname = sname;}//省略Getter 和 Setter 方法//省略toString方法
}

原因分析:

使用类的query方法时,传入的类没有无参构造

解决方案:

cannotcreate__连网时出现错误651怎么解决

原因:.query(, sql, new (type), args);

使用 new 还有 new 时 ,传入的实体类加入无参构造即可

(1)里面的属性要有set方法

(2)类里面如果有带参数的改造方法,必须添加一个没有参数的构造方法

(3)查询语句sql = id, sname, , brand, , sales, stock from where id = ?; 里面的参数保证类里面有同名的构造方法;

正确代码

public class Goods {private Integer id;          //商品编号private String sname;        //商品名public Goods(){}	//空构造public Goods(Integer id, String sname) {this.id = id;this.sname = sname;}//省略Getter 和 Setter 方法//省略toString方法
}

tags: dbutils

关于我们

最火推荐

小编推荐

联系我们


版权声明:本站内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 88@qq.com 举报,一经查实,本站将立刻删除。备案号:桂ICP备2021009421号
Powered By Z-BlogPHP.
复制成功
微信号:
我知道了