您好,goods商品表是mysql数据库中的一张商品信息表,GoodsDAO继承BasicDAO,末段代码为运行时报错内容,其中druid配置信息等如下,求解,非常3Q
```java
#key=value
driverClassName=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/lhc_db03?rewriteBatchedStatements=true
username=root
password=lhc
#initial connection Size
initialSize=10
#min idle connecton size
minIdle=5
#max active connection size
maxActive=50
#max wait time (5000 mil seconds)
maxWait=5000
```java
package dao_.dao;
import dao_.utils.JDBCUtilsByDruid;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
public class BasicDAO<T> {
private QueryRunner qr = new QueryRunner();
public int update(String sql,Object...parameters){
Connection connection = null;
try {
connection = JDBCUtilsByDruid.getConnection();
int update = qr.update(connection,sql,parameters);
return update;
} catch (SQLException e) {
throw new RuntimeException(e);
} finally {
JDBCUtilsByDruid.close(null,null,connection);
}
}
public List<T> queryMulti(String sql,Class<T> clazz,Object...parameters){
Connection connection = null;
try {
connection = JDBCUtilsByDruid.getConnection();
return qr.query(connection,sql,new BeanListHandler<T>(clazz),parameters);
} catch (SQLException e) {
throw new RuntimeException(e);
} finally {
JDBCUtilsByDruid.close(null,null,connection);
}
}
public T querySingle(String sql,Class<T> clazz,Object...parameters){
Connection connection = null;
try {
connection=JDBCUtilsByDruid.getConnection();
return qr.query(connection,sql,new BeanHandler<T>(clazz),parameters);
} catch (SQLException e) {
throw new RuntimeException(e);
} finally {
JDBCUtilsByDruid.close(null,null,connection);
}
}
public Object queryScalar(String sql,Object...parameters){
Connection connection = null;
try {
connection = JDBCUtilsByDruid.getConnection();
return qr.query(connection,sql,new ScalarHandler(),parameters);
} catch (SQLException e) {
throw new RuntimeException(e);
} finally {
JDBCUtilsByDruid.close(null,null,connection);
}
}
}
package dao_.dao;
public class GoodsDAO extends BasicDAO{
}
```java
package dao_.domain;
public class Goods {
private int id;
private String goods_name;
private double price;
public Goods(int id, String goods_name, double price) {
this.id = id;
this.goods_name = goods_name;
this.price = price;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getGoods_name() {
return goods_name;
}
public void setGoods_name(String goods_name) {
this.goods_name = goods_name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
@Override
public String toString() {
return "Goods{" +
"id=" + id +
", goods_name='" + goods_name + '\'' +
", price=" + price +
'}';
}
}
package dao_.domain;
public class Goods {
private int id;
private String goods_name;
private double price;
public Goods(int id, String goods_name, double price) {
this.id = id;
this.goods_name = goods_name;
this.price = price;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getGoods_name() {
return goods_name;
}
public void setGoods_name(String goods_name) {
this.goods_name = goods_name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
@Override
public String toString() {
return "Goods{" +
"id=" + id +
", goods_name='" + goods_name + '\'' +
", price=" + price +
'}';
}
}
```java
一月 31, 2024 9:50:27 上午 com.alibaba.druid.pool.DruidDataSource info
信息: {dataSource-1} inited
Exception in thread "main" java.lang.RuntimeException: java.sql.SQLException: Cannot create dao_.domain.Goods: dao_.domain.Goods Query: select * from goods where price >= ? Parameters: [2000]
at dao_.dao.BasicDAO.queryMulti(BasicDAO.java:35)
at dao_.test.TestGoodsDAO.main(TestGoodsDAO.java:11)
Caused by: java.sql.SQLException: Cannot create dao_.domain.Goods: dao_.domain.Goods Query: select * from goods where price >= ? Parameters: [2000]
at org.apache.commons.dbutils.QueryRunner.rethrow(QueryRunner.java:542)
at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:399)
at dao_.dao.BasicDAO.queryMulti(BasicDAO.java:33)
... 1 more
Process finished with exit code 1