在productDaoImpl 实现查询分类信息,我的实现办法如下:
public List<Product> findAll() {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs=null;
List<Product> list=null;
CategoryService cService=new CategoryServiceImpl();
try {
conn=JDBCUtils.getConnection();
String sql="select * from product";
pstmt=conn.prepareStatement(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.setDescription(rs.getString("description"));
product.setPrice(rs.getDouble("price"));
product.setFilename(rs.getString("filename"));
product.setPath(rs.getString("path"));
product.setCategory(cService.findOne(rs.getInt("cid")));
list.add(product);
}
return list;
}catch (Exception e) {
e.printStackTrace();
}finally {
JDBCUtils.release(rs, pstmt, conn);
}
return null;
}请问老师,这样查询方法和您讲的那个联合查询,有什么优缺点?
4
收起
正在回答 回答被采纳积分+1
4回答
相似问题
登录后可查看更多问答,登录/注册
3. Java 数据库开发与实战应用
- 参与学习 人
- 提交作业 357 份
- 解答问题 8016 个
本阶段将带你学习MySQL数据库,JDBC接口,MyBatis框架等,带你掌握的数据的存放和管理。
了解课程


恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星