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

📄 kinddbaccess.java

📁 功能描述 1) 后台:管理员负责对整个论坛进行管理
💻 JAVA
字号:
/**
 *数据库类:负数版块的增、删、改、查
 */
package bbs.db;

import com.db.*;
import java.sql.*;
import java.util.ArrayList;
import bbs.bean.BbsKinds;
import java.util.*;
import bbs.bean.BbsSection;

public class KindDBAccess
    extends Databasec {
  private ResultSet res = null;
  private String tabName = null;
  public ArrayList select(String tabName) throws Exception {
    return null;
  }

  /**
   * 插入方法:向数据库增加版块
   * @param obj BbsKinds
   * @return int
   * @throws Exception
   */
  public int insert(BbsKinds obj) throws Exception {
    try {
      this.open();
      String sql = "insert into bbsKinds values(?,?)";
      pst = con.prepareStatement(sql);
      pst.setString(1, obj.getKname());
      pst.setString(2, obj.getKdate());
      return pst.executeUpdate();
    }
    finally {
      this.close();
    }
  }

  /**
   * 插入方法
   * 向子版块插入数据
   * @param obj BbsSection
   * @return int
   * @throws Exception
   */
  public int insertSection(BbsSection obj) throws Exception {
    try {
      this.open();
      String sql =
          "insert into BbsSection(KID,Sname,Sprofile,Sdate) values(?,?,?,?)";
      pst = con.prepareStatement(sql);
      pst.setInt(1, obj.getKid());
      pst.setString(2, obj.getKname());
      pst.setString(3, obj.getSprofile());
      pst.setString(4, obj.getKdate());
      return pst.executeUpdate();
    }
    finally {
      this.close();
    }
  }
  /**
   * 查询所有子版块
   * @return ArrayList
   * @throws Exception
   */
  public ArrayList selectSection() throws Exception {
    ArrayList list = new ArrayList();
    try {
      this.open();
      String sql = "select * from bbsSection";
      pst = con.prepareStatement(sql);
      res = pst.executeQuery();
      while (res.next()) {
        BbsSection obj = new BbsSection();
        obj.setKid(res.getInt("SID"));
        obj.setKname(res.getString("Sname"));
        obj.setKdate(res.getString("Sdate"));
        list.add(obj);
      }
    }
    finally {
      this.close();
    }
    return list;
  }
  /**
   * 查询某个父版块的所有子版块
   * @param kid String
   * @return ArrayList
   * @throws Exception
   */
  public ArrayList selectSubSection(String kid) throws Exception {
    ArrayList list = new ArrayList();
    try {
      this.open();
      String sql = "select * from bbsSection where kid=" + kid;
      pst = con.prepareStatement(sql);
      res = pst.executeQuery();
      while (res.next()) {
        BbsSection obj = new BbsSection();
        obj.setKid(res.getInt("SID"));
        obj.setKname(res.getString("Sname"));
        obj.setKdate(res.getString("Sdate"));
        list.add(obj);
      }
    }
    finally {
      this.close();
    }
    return list;
  }

  /**
   * 负表查询数据库现有的所有版块
   * @return ArrayList
   * @throws Exception
   */
  public ArrayList select() throws Exception {
    ArrayList list = new ArrayList();
    try {
      this.open();
      String sql = "select * from bbsKinds";
      pst = con.prepareStatement(sql);
      res = pst.executeQuery();
      while (res.next()) {
        BbsKinds obj = new BbsKinds();
        obj.setKid(res.getInt("KID"));
        obj.setKname(res.getString("KName"));
        obj.setKdate(res.getString("KDate"));
        list.add(obj);
      }
    }
    finally {
      this.close();
    }
    return list;
  }
  /**
   * 更新版块信息
   * @param obj BbsSection
   * @return int
   * @throws Exception
   */
  public int updateSection(BbsSection obj) throws Exception {
    try {
      this.open();
      String sql = "update BbsSection set SName=?,SDate=? where SID=?";
      pst = con.prepareStatement(sql);
      pst.setString(1, obj.getSname());
      pst.setString(2, obj.getKdate());
      pst.setInt(3, obj.getSid());
      System.out.println("name=" + obj.getSname());
      System.out.println("date=" + obj.getKdate());
      System.out.println("id=" + obj.getSid());
      return pst.executeUpdate();
    }
    finally {
      this.close();
    }
  }
  /**
   * 删除版块
   * 根据编号进行删除
   * @param id String
   * @return int
   * @throws Exception
   */
  public int deleteSection(String id) throws Exception {
    try {
      this.open();
      String sql = "delete from bbsSection where SID=" + id;
      pst = con.prepareStatement(sql);
      return pst.executeUpdate();
    }
    finally {
      this.close();
    }

  }

  /**
   * 修改方法:负责对版块的修改操作
   * @param obj BbsKinds
   * @return int
   * @throws Exception
   */
  public int update(BbsKinds obj) throws Exception {
    try {
      this.open();
      String sql = "update bbsKinds set KName=?,KDate=? where KID=?";
      pst = con.prepareStatement(sql);
      pst.setString(1, obj.getKname());
      pst.setString(2, obj.getKdate());
      pst.setInt(3, obj.getKid());
      return pst.executeUpdate();
    }
    finally {
      this.close();
    }
  }

  /**
   * 删除方法:用于对数据库里面的版块进行删除
   * @param id String
   * @return int
   * @throws Exception
   */
  public int delete(String id) throws Exception {
    try {
      this.open();
      String sql = "delete from bbsSection where KID=" + id;
      pst = con.prepareStatement(sql);
      pst.executeUpdate();
      sql = "delete from bbsKinds where KID=" + id;
      pst = con.prepareStatement(sql);
      return pst.executeUpdate();
    }
    finally {
      this.close();
    }

  }
}

⌨️ 快捷键说明

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