- publicstaticvoidgetCategories(List<Category>list,intid)
- {
- Connectionconn=null;
- try
- {
- conn=DB.getConn();
- getCategories(conn,list,id);
- }finally
- {
- DB.closeConn(conn);
- }
- }
- privatestaticvoidgetCategories(Connectionconn,List<Category>list,intid)
- {
- ResultSetrs=null;
- try
- {
- Stringsql="select*fromcategorywherepid="+id;
- rs=DB.executeQuery(conn,sql);
- while(rs.next())
- {
- Categoryc=newCategory();
- c.setId(rs.getInt("id"));
- c.setName(rs.getString("name"));
- c.setDescr(rs.getString("descr"));
- c.setLeaf(rs.getBoolean("isleaf")?true:false);
- c.setPid(rs.getInt("pid"));
- c.setGrade(rs.getInt("grade"));
- list.add(c);
- if(c.isLeaf())
- {
- getCategories(conn,list,c.getId());
- }
- }
- }catch(SQLExceptione)
- {
- e.printStackTrace();
- }finally
- {
- DB.closeRs(rs);
- }
- }
- 把CONN也作为其中的一个参数传过去就可以避免建立CONN太多的问题了,
建立CONN太多的解决方法--shopping
最新推荐文章于 2024-07-19 10:24:14 发布