package com.tarena.dao.impl; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import com.tarena.dao.CategoryDAO; import com.tarena.entity.Category; import com.tarena.util.DBConnection; public class CategoryDAOImpl implements CategoryDAO { private static final String FIND_ALL = "select * from d_category"; private static final String FIND_BY_PARENT_ID = "select dc.*,count(dcp.product_id) as pnum " + "from d_category dc left outer join d_category_product dcp " + "on dc.id=dcp.cat_id " + "where dc.parent_id=? " + "group by dc.id"; public List<Category> findAll() throws Exception { Connection conn = null; PreparedStatement prep = null; ResultSet rs = null; List<Category> cats = new ArrayList<Category>(); try { prep = DBConnection.getConnection().prepareStatement(FIND_ALL); rs = prep.executeQuery(); while (rs.next()) { Category c = new Category(); c.setDescription(rs.getString("description")); c.setEn_name(rs.getString("en_name")); c.setId(rs.getInt("id")); c.setName(rs.getString("name")); c.setParent_id(rs.getInt("parent_id")); cats.add(c); } } finally { DBConnection.close(rs, prep, conn); } return cats; } public List<Category> findByParentId(int pid) throws Exception { Connection conn = null; PreparedStatement prep = null; ResultSet rst= null; List<Category> cats = new ArrayList<Category>(); try { prep = DBConnection.getConnection().prepareStatement(FIND_BY_PARENT_ID); prep.setInt(1, pid); rst= prep.executeQuery(); while(rst.next()){ Category c = new Category(); c.setId(rst.getInt("id")); c.setEn_name(rst.getString("en_name")); c.setName(rst.getString("name")); c.setTurn(rst.getInt("turn")); c.setParent_id(rst.getInt("parent_id")); c.setDescription(rst.getString("description")); c.setPnum(rst.getInt("pnum")); cats.add(c); } } finally { DBConnection.close(rst, prep, conn); } return cats; } }


微信网友_6680567232876544 LV8
2023年10月7日
SDLFJL LV6
2023年7月23日
KaoPu trips LV2
2023年6月15日
95959595959 LV13
2023年3月18日
微信网友_6270418622812160 LV3
2022年12月20日
wwwqwert LV1
2022年12月6日
微信网友_6191704594370560 LV1
2022年10月26日
你相信爱情吗 LV1
2022年10月24日
627526996 LV8
2022年8月2日
明天下午去 LV2
2022年6月15日