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

📄 kind.java

📁 本系统分两部分管理,前台用于文章发布和用户文章发表,后台有管理员审核和不同权限的用户管理,具有高稳定性和安全性。整个站的全部数据逻辑运算完全有beans封装, 具有界面简洁、功能强大、操作方便等特点。
💻 JAVA
字号:
package com.ntsky.news.manage;

/**
 * <p>Title: NTsky新闻发布v1.0正式版</p>
 * <p>Description: 类的相关操作</p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: NTsky</p>
 * @authory 姚君林
 * @version 1.0
 */
import java.io.*;
import java.sql.*;
import java.util.*;

import com.ntsky.common.*;
import com.ntsky.database.*;
import com.ntsky.persistence.*;

public class Kind {
    private SQLDBOperator sdbo=null;
    /**
     * 显示数据库中已有类别
     */
    //判断类别是否为空
    public boolean isNullKind(int classId){
        boolean isNull=false;
        if (sdbo==null)
            sdbo = SQLDBOperator.getInstance("Connection");
        ResultSet rs=null;
        String Sql="select kindId from newskind where classId=?;";
        sdbo.prepareStatement(Sql);
        sdbo.setInt(1,classId);
        rs=sdbo.executeQuery();
        try{
            rs.last();
            if(rs.getRow()>0){
                isNull=true;
                rs.close();
            }
        }
        catch(Exception e){
            e.printStackTrace(System.out);
            Debug.writeLog("Kind inNullKind(), Exception Occured ! Info :" + e.getLocalizedMessage());
        }
        sdbo.Close();
        return isNull;
    }
    //列出所有的类别
    public Iterator allKind(){
        ResultSet rs=null;
        if (sdbo==null)
            sdbo = SQLDBOperator.getInstance("Connection");
        Vector vector=new Vector();
        String Sql="select kindId,content,classId from newskind;";
        rs=sdbo.executeQuery(Sql);
        try{
            while(rs.next()){
                NEWSKind tableKind = new NEWSKind();
                tableKind.setKindId(rs.getInt("kindId"));
                tableKind.setContent(rs.getString("content"));
                tableKind.setClassId(rs.getInt("classId"));
                vector.add(tableKind);
            }
            rs.close();
        }
        catch(Exception e){
            e.printStackTrace(System.out);
            Debug.writeLog("Kind getKind(), Exception Occured ! Info :" + e.getLocalizedMessage());
        }
        sdbo.Close();
        return vector.iterator();
    }
    //列出满足条件的类别
    public Iterator getKind(int classId){
        ResultSet rs=null;
        if (sdbo==null)
            sdbo = SQLDBOperator.getInstance("Connection");
        Vector vector=new Vector();
        String Sql="select kindId,content,classId from newskind where classId=?;";
        sdbo.prepareStatement(Sql);
        sdbo.setInt(1,classId);
        rs=sdbo.executeQuery();
        try{
            while(rs.next()){
                NEWSKind tableKind = new NEWSKind();
                tableKind.setKindId(rs.getInt("kindId"));
                tableKind.setContent(rs.getString("content"));
                tableKind.setClassId(rs.getInt("classId"));
                vector.add(tableKind);
            }
            rs.close();
        }
        catch(Exception e){
            e.printStackTrace(System.out);
            Debug.writeLog("Kind getKind(), Exception Occured ! Info :" + e.getLocalizedMessage());
        }
        sdbo.Close();
        return vector.iterator();
    }
    /**
     * 插入类别
     */
    public void insKind(String content,int classId) throws SQLException{
        if (sdbo==null)
            sdbo = SQLDBOperator.getInstance("Connection");
        String sql = "insert into newskind(content,classId) values(?,?);";
        sdbo.prepareStatement(sql);
        sdbo.setString(1,CodeFilter.toHtml(content));
        sdbo.setInt(2,classId);
        sdbo.executeUpdate();
        sdbo.Close();
    }
    /**
     * 删除类别
     */
    public void delKind(int kindId) throws SQLException{
        if (sdbo==null)
            sdbo = SQLDBOperator.getInstance("Connection");
        String sql_kind = "delete from newskind where kindId=?;";
        String sql_news = "delete from news where kindId=?;";
        String sql_news_newsId = "select newsId from news where kindId=?";
        String sql_reply = "delete from newsreply where newsId=?;";
        //删除类别
        sdbo.prepareStatement(sql_kind);
        sdbo.setInt(1,kindId);
        sdbo.executeUpdate();
        //删除新闻
        sdbo.prepareStatement(sql_news);
        sdbo.setInt(1,kindId);
        sdbo.executeUpdate();
        /**
         * 删除回复
         */
        sdbo.prepareStatement(sql_news_newsId);
        sdbo.setInt(1,kindId);
        ResultSet rs=sdbo.executeQuery();
        sdbo.prepareStatement(sql_reply);
        while(rs.next()){
            int newsId=rs.getInt("newsId");
            sdbo.setInt(1,newsId);
            sdbo.executeUpdate();
        }
        sdbo.Close();
    }
    /**
     * 修改类别
     */
    public Iterator editKind(int kindId){
        if (sdbo==null)
            sdbo = SQLDBOperator.getInstance("Connection");
        String sql = "select * from newskind where kindId=?";
        Vector vector = new Vector();
        try{
            sdbo.prepareStatement(sql);
            sdbo.setInt(1,kindId);
            ResultSet rs = sdbo.executeQuery();
            while(rs.next()){
                NEWSKind tableKind = new NEWSKind();
                tableKind.setContent(rs.getString("content"));
                tableKind.setClassId(rs.getInt("classId"));
                vector.add(tableKind);
            }
        }
        catch(Exception e){
            Debug.writeLog("Kind editKind(), Exception Occured ! Info :" + e.getLocalizedMessage());
        }
        sdbo.Close();
        return vector.iterator();
    }
    /**
     * 更新记录
     */
    public void upKind(int classId,String content,int kindId) throws Exception{
        if (sdbo==null)
            sdbo = SQLDBOperator.getInstance("Connection");
        String sql = "update newskind set classId=?,content=? where kindId=?;";
        sdbo.prepareStatement(sql);
        sdbo.setInt(1,classId);
        sdbo.setString(2,CodeFilter.toHtml(content));
        sdbo.setInt(3,kindId);
        sdbo.executeUpdate();
        sdbo.Close();
    }
}

⌨️ 快捷键说明

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