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

📄 newproduct.java~14~

📁 对项目
💻 JAVA~14~
字号:
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 csk
 * @version 1.0
 */

public class NewProduct {

  public NewProduct() {
  }
  public static void main(String[] args) {
    NewProduct newProduct1 = new NewProduct();
  }

  /**添加一种产品
   *
   * @param pd(产对象实例)
   * @return 无
   */
  public void addProduct(Product pd)
  {
    db=DBConnectionManager.getInstance();
    con=db.getConnection("idb");
    long maxid=0;
    try {
      PreparedStatement ps1 = con.prepareStatement("select max(product_id) as id from product");
      rs =ps1.executeQuery();
      if(rs.next() ){
        maxid = rs.getLong("id")+1 ;
      }
      else
        maxid=1;
      if(ps1!=null)
        ps1.close();
    }
    catch (SQLException ex) {
      ex.printStackTrace() ;
    }
    String sql="insert into product(product_id,product_name,type_id,product_content,maker_id)values(?,?,?,?,?)";
    try {
      ps=con.prepareStatement(sql);
      ps.setLong(1,maxid);
      ps.setString(2,pd.getProduct_name()) ;
      ps.setLong(3,pd.getType_id());
      ps.setString(4,pd.getProduct_content());
      ps.setLong(5,pd.getMaker_id());
      ps.executeUpdate();
    }
    catch (SQLException ex) {
      freeCon();
      ex.printStackTrace();
    }
    freeCon();
  }

  /**根据产品id删除该产品,其中在删除该产品时页删除ppm表中与该产品相关的记录
   *
   * @param pdid(产品id)
   * @return 无
   */
  public void delProductid(long pdid)
  {
    db=DBConnectionManager.getInstance();
    con=db.getConnection("idb");
    String sql="delete from product where product_id=?";
    try {
      ps=con.prepareStatement(sql);
      ps.setLong(1,pdid);
      ps.executeUpdate();
      //删除所有的ppm表中的该产品记录
      NewPPM newppm=new NewPPM();
      newppm.delPPMProductid(pdid);
      newppm.freeCon();
    }
    catch (SQLException ex) {
      ex.printStackTrace();
    }
  }

  /**更新一个产品信息
   * @param Product pd(产品对象实例)
   * @return 无
   */

  public void upateProduct(Product pd)
  {
    db=DBConnectionManager.getInstance();
    con=db.getConnection("idb");
    String sql="update product set product_name=?,type_id=?,product_content=?,maker_id=? where product_id=?";
    try {
      ps=con.prepareStatement(sql);
      ps.setString(1,pd.getProduct_name());
      ps.setLong(2,pd.getType_id());
      ps.setString(3,pd.getProduct_content());
      ps.setLong(4,pd.getMaker_id());
      ps.setLong(5,pd.getProduct_id());

      ps.executeUpdate();
    }
    catch (SQLException ex) {
      freeCon();
      ex.printStackTrace();
    }
    freeCon();
  }

  /**根据类别id删除产品表中的有关产品
   *
   * @param typeid(类别id)
   * @return 无
   */
  public void delProductUpid(long typeid)
  {
    db=DBConnectionManager.getInstance();
    con=db.getConnection("idb");
    String sql="select *from product where type_id=?";
    try {
      ps=con.prepareStatement(sql);
      ps.setLong(1,typeid);
      rs=ps.executeQuery();
      while(rs.next())
      {
        delProductid(rs.getLong("product_id"));//调用删除产品方法
      }
    }
    catch (SQLException ex) {
      freeCon();
      ex.printStackTrace();
    }
    freeCon();
  }

  /**根据厂商id删除产品表中的有关产品
   *
   * @param long mkid(厂商id)
   * @return 无
   */
  public void delProductMakerid(long mkid)
  {
    db=DBConnectionManager.getInstance();
    con=db.getConnection("idb");
    String sql="select *from product where maker_id=?";
    try {
      ps=con.prepareStatement(sql);
      ps.setLong(1,mkid);
      rs=ps.executeQuery();
      while(rs.next())
      {
        delProductid(rs.getLong("product_id"));//调用删除产品方法
      }
    }
    catch (SQLException ex) {
      freeCon();
      ex.printStackTrace();
    }
    freeCon();
  }

  /**根据厂商id获得属于该厂商的所有id
   *
   * @param maker_id
   * @return
   */
  public Vector getProductMakerid(long maker_id)
  {
    Basic basic=new Basic();
    Vector list=new Vector();
    db=DBConnectionManager.getInstance();
    con=db.getConnection("idb");
    String sql="select *from product where maker_id=?";
    try {
      ps=con.prepareStatement(sql);
      ps.setLong(1,maker_id);
      rs=ps.executeQuery();
      while(rs.next())
      {
        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(rs.getString("product_content"));
        pd.setMaker_id(rs.getLong("maker_id"));
        list.add(pd);
      }
    }
    catch (SQLException ex) {
      ex.printStackTrace();
    }

    freeCon();
    return list;
  }

  /**
   * 释放数据库资源<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) ;
  }

  private PreparedStatement ps=null;
  private DBConnectionManager db;
  private Connection con=null;
  private ResultSet rs=null;
}

⌨️ 快捷键说明

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