⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 productmanager.java~7~

📁 jsp数据库系统
💻 JAVA~7~
字号:
package zhaobiao.db;

import java.util.*;
import java.sql.*;
import zhaobiao.db.*;
import zhaobiao.data.*;

/**
 * <p>Title: 产品信息管理类</p>
 * <p>Description: 有关产品的浏览操作</p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: </p>
 * @author unascribed
 * @version 1.0
 */

public class ProductManager {

  public ProductManager() {
  }

  /**  根据项目id获得该项目对象
     *
     *
     */
    public Project getProject(long project_id)
    {
      Project pj=new Project();
      db=DBConnectionManager.getInstance();
      con=db.getConnection("idb");
      String sql="select *from project where project_id=?";
      try {
        ps=con.prepareStatement(sql);
        ps.setLong(1,project_id);
        rs=ps.executeQuery();
        if(rs.next())
        {
          pj.setProject_id(rs.getLong("project_id"));
          pj.setProject_name(rs.getString("project_name"));
          pj.setProject_time(rs.getString("project_time"));
          pj.setProject_company(rs.getString("project_company"));
          pj.setProject_cost(rs.getString("project_cost"));
          pj.setProject_content(rs.getString("project_content"));
        }
      }
      catch (SQLException ex) {
        freeCon();
        ex.printStackTrace();
      }
      freeCon();
      return pj;
  }
  /**  根据类别的id获得该类别对象
   *
   *
   */
  public Type getType(long type_id)
  {
    Type type=new Type();
    db=DBConnectionManager.getInstance();
    con=db.getConnection("idb");
    String sql="select *from type where type_id=?";
    try {
      ps=con.prepareStatement(sql);
      ps.setLong(1,type_id);
      rs=ps.executeQuery();
      if(rs.next())
      {
        type.setType_id(rs.getLong("type_id"));
        type.setType_name(rs.getString("type_name"));
        type.setType_content(rs.getString("type_content"));

      }
    }
    catch (SQLException ex) {
      ex.printStackTrace();
      freeCon();
    }
    freeCon();
    return type;
  }

  /**根据产品id获得该产品对象
 *
 *
 */
  public Product getProduct(long product_id)
  {
    Product pd=new Product();
    db=DBConnectionManager.getInstance();
    con=db.getConnection("idb");
    String sql="select *from product where product_id=?";
    try {
      ps=con.prepareStatement(sql);
      ps.setLong(1,product_id);
      rs=ps.executeQuery();
      if(rs.next())
      {
        pd.setProduct_id(rs.getLong("product_id"));
        pd.setProduct_name(rs.getString("product_name"));
        pd.setType_id(rs.getLong("type_id"));
        pd.setProduct_content(rs.getString("product_content"));

      }
    }
    catch (SQLException ex) {
      freeCon();
      ex.printStackTrace();
    }
    freeCon();
    return pd;

  }


  /**  获得所有的类别集合
   *
   *
   */
  public Vector getTypeList()
  {
    Vector list=new Vector();
    db=DBConnectionManager.getInstance();
    con=db.getConnection("idb");
    String sql="select *from type";
    try {
      ps=con.prepareStatement(sql);
      rs=ps.executeQuery();
      while(rs.next())
      {
        Type type=new Type();
        type.setType_id(rs.getLong("type_id"));
        type.setType_name(rs.getString("type_name"));
        type.setType_content(rs.getString("type_content"));
        list.add(type);
      }
    }
    catch (SQLException ex) {
      freeCon();
      ex.printStackTrace();
    }
    freeCon();
    return list;

  }

  /**  获得类别下的所有产品集合
   *
   *
   */
  public  Vector getProductList(long page ,long pagemax,long type_id)
  {
     page=page-1;
    Vector list=new Vector();
    db=DBConnectionManager.getInstance();
    con=db.getConnection("idb");
    String sql="select *from product where type_id=?";
    try {
      ps=con.prepareStatement(sql);
      ps.setLong(1,type_id) ;
      rs=ps.executeQuery();
      int count=1;
      while(rs.next())
      {
        if (count>(page*pagemax)&&count<=(page*pagemax+pagemax)){
        Product pd=new Product();
        pd.setProduct_id(rs.getLong("product_id"));
        pd.setProduct_name(rs.getString("product_name"));
        pd.setType_id(rs.getLong("type_id"));
        pd.setProduct_content("product_content");
        list.add(pd);
        }
        count++;
      }
    }
    catch (SQLException ex) {
      freeCon();
      ex.printStackTrace();
    }
    freeCon();
    return list;
  }

  /**  根据该产品id获得PPM表中的项目集合(去掉PPM表中重复的project_id)
   *
   *
   */
  public Set getProjectList(long page ,long pagemax,long product_id)
  {
    page=page-1;
    Set set1=new TreeSet();
    db=DBConnectionManager.getInstance();
    con=db.getConnection("idb");
    String sql="select *from ppm where product_id=?";
    try {
      ps=con.prepareStatement(sql);
      ps.setLong(1,product_id);
      rs=ps.executeQuery();
      int count=1;
      while(rs.next())
      {
        if (count>(page*pagemax)&&count<=(page*pagemax+pagemax)){
        long projectid;
        Project pj=new Project();
        projectid=rs.getLong("project_id");
        pj=getProject(projectid);
        if(set1.add(pj))
          count++;
        }
      }
    }
    catch (SQLException ex) {
      freeCon();
      ex.printStackTrace();
    }
    freeCon();
    return set1;
  }

  /**
  * 释放数据库资源<p>
  *PreparedStatement和ResultSep将关闭,Connection返回给连接池
  * @param      无
  * @repurn     无
  * @exception  SQLException
  *
  */
 public void freeCon(){
   try {
     if (rs!=null)
       rs.close() ;
     if (ps!=null)
       ps.close() ;
   }
   catch (SQLException ex) {
   }
   if (db!=null)
   db.freeConnection("idb",con) ;
  }

  public static void main(String[] args) {
    ProductManager productManager1 = new ProductManager();
  }
  private DBConnectionManager db;
  private Connection con=null;
   private ResultSet rs=null;
  private PreparedStatement ps=null;
  private WSResultSet ws=null;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -