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

📄 newtype.java

📁 对项目
💻 JAVA
字号:
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 NewType {

  public NewType() {
  }

  /**添加一个新类别
   *
   * @param type(类别对象实例)
   * @return 无
   */
  public void addType(Type type)
  {
    db=DBConnectionManager.getInstance();
    con=db.getConnection("idb");
    long maxid=0;
    try {
      PreparedStatement ps1 = con.prepareStatement("select max(type_id) as id from type");
      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 type(type_id,type_name,Type_content) values(?,?,?)";
    try {
      ps=con.prepareStatement(sql);
      ps.setLong(1,maxid);
      ps.setString(2,type.getType_name());
      ps.setString(3,type.getType_content() );
      ps.executeUpdate();
    }
    catch (SQLException ex) {
      freeCon();
      ex.printStackTrace();
    }
    freeCon();
  }

  /**更新一个类别
   *
   * @param type(类别对象实例)
   * @return 无
   */
  public void updateType(Type type)
  {
    db=DBConnectionManager.getInstance();
    con=db.getConnection("idb");
    String sql="update type set type_name=?,type_content=? where type_id=?";
    try {
      ps=con.prepareStatement(sql);
      ps.setString(1,type.getType_name());
      ps.setString(2,type.getType_content());
      ps.setLong(3,type.getType_id());
      ps.executeUpdate();
    }
    catch (SQLException ex) {
      freeCon();
      ex.printStackTrace();
    }
    freeCon();
  }

  /**根据类别id删除该类别,调用NewProject中的删除方法delProjectTypeid(typeid)
   * 删除项目_类别关联表中的记录,调用NewProduct中的delProductUpid(typeid)
   * 删除该类别下的所有产品
   *
   * @param typeid
   */
  public void delType(long typeid)
  {
    db=DBConnectionManager.getInstance();
    con=db.getConnection("idb");
    String sql="delete from type where type_id=?";
    try {
      ps=con.prepareStatement(sql);
      ps.setLong(1,typeid);
      ps.executeUpdate();
      NewProject newpj=new NewProject();             //调用NewProject中的删除方法
      newpj.delProjectTypeid(typeid);
      newpj.freeCon();
                                                 //删除属于该类别的所有产品
      NewProduct newpd=new NewProduct();
      newpd.delProductUpid(typeid);
      newpd.freeCon();
    }
    catch (SQLException ex) {
      freeCon();
      ex.printStackTrace();
    }
    freeCon();
  }


  /**  获得所有的类别集合
   * @param 无
   * @return Vector类别集合
   */

  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 static void main(String[] args) {
    NewType newType1 = new NewType();
  }

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