product.setFilename(rs.getString("filename"));单行报错
来源:4-3 列表显示的DAO的编写
慕姐6114392
2020-04-19 02:02:00
package com.imooc.dao.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import com.imooc.dao.ProductDao;
import com.imooc.domain.Product;
import com.imooc.utils.JDBCUtils;
import com.mysql.cj.protocol.Resultset;
public class ProductDaoImpl implements ProductDao {
@Override
public List<Product> findAll() {
System.out.println("1111111111");
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
List<Product> list = null;
try{
// 获得连接
conn = JDBCUtils.getConnection();
// 编写sql
String sql = "select * from product p,category c where p.cid = c.cid";
// 预编译sql
pstmt = conn.prepareStatement(sql);
// 执行sql
rs = pstmt.executeQuery();
// 遍历结果集
list = new ArrayList<Product>();
while(rs.next()){
Product product = new Product();
product.setPid(rs.getInt("pid"));
product.setPname(rs.getString("pname"));
product.setAuthor(rs.getString("author"));
product.setPrice(rs.getDouble("price"));
product.setDescription(rs.getString("description"));
product.setFilename(rs.getString("filename"));
product.setPath(rs.getString("path"));
// 封装商品的分类
product.getCategory().setCid(rs.getInt("cid"));
product.getCategory().setCname(rs.getString("cname"));
product.getCategory().setCdesc(rs.getString("cdesc"));
list.add(product);
}
}catch(Exception e){
e.printStackTrace();
}finally{
JDBCUtils.release(rs, pstmt, conn);
}
return list;
}
}


3回答
好帮手慕小班
2020-04-19
同学你好,根据报错信息:The method setFilename(String) is undefined for the type Product-->Product未定义方法setFilename(String)
由上述内容可知在实体类Product中,同学没有定义类型的String的setFilename方法,同学可以检查一下自己的Product类,是不是没有setFilename方法。
如果我的回答解决了你的疑惑,请采纳,祝学习愉快~
慕姐6114392
提问者
2020-04-19

慕姐6114392
提问者
2020-04-19
都是同一个数据表的怎么就他没定义呢?[object Object]
相似问题