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

📄 news.java

📁 动态网站管理发布系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.ntsky.news.manage;

import com.ntsky.common.*;
import com.ntsky.database.SQLDBOperator;
import com.ntsky.persistence.NEWSReply;
import com.ntsky.persistence.NEWSTable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.Vector;

public class News
{

    private SQLDBOperator sdbo;

    public News()
    {
        sdbo = null;
    }

    public void insNews(int classId, int kindId, int myOther, String headTitle, String content, String connect, String author, 
            String editor, String newsFrom, int top)
    {
        if(sdbo == null)
            sdbo = SQLDBOperator.getInstance("Connection");
        String sql = "insert into news(classId,kindId,myOther,headTitle,content,connect,author,editor,newsFrom,top,newsTime,state,tag) values(?,?,?,?,?,?,?,?,?,?,?,1,1);";
        try
        {
            sdbo.prepareStatement(sql);
            sdbo.setInt(1, classId);
            sdbo.setInt(2, kindId);
            sdbo.setInt(3, myOther);
            sdbo.setString(4, CodeFilter.toHtml(headTitle));
            sdbo.setString(5, CodeFilter.toHtml(content));
            sdbo.setString(6, CodeFilter.toHtml(connect));
            sdbo.setString(7, CodeFilter.toHtml(author));
            sdbo.setString(8, CodeFilter.toHtml(editor));
            sdbo.setString(9, CodeFilter.toHtml(newsFrom));
            sdbo.setInt(10, top);
            sdbo.setString(11, DateUtil.getNowDate());
            sdbo.executeUpdate();
        }
        catch(Exception sqlE)
        {
            System.out.print("News insNews() " + sqlE.getMessage());
            Debug.writeLog("News insNews(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
        }
        finally
        {
            sdbo.Close();
        }
    }

    public void insUbbNews(int classId, int kindId, int myOther, String headTitle, String content, String connect, String author, 
            String editor, String newsFrom, int top)
    {
        if(sdbo == null)
            sdbo = SQLDBOperator.getInstance("Connection");
        String sql = "insert into news(classId,kindId,myOther,headTitle,content,connect,author,editor,newsFrom,top,newsTime,state,tag) values(?,?,?,?,?,?,?,?,?,?,?,1,1);";
        try
        {
            sdbo.prepareStatement(sql);
            sdbo.setInt(1, classId);
            sdbo.setInt(2, kindId);
            sdbo.setInt(3, myOther);
            sdbo.setString(4, CodeFilter.toHtml(headTitle));
            sdbo.setString(5, CodeFilter.toUbbHtml(content));
            sdbo.setString(6, CodeFilter.toHtml(connect));
            sdbo.setString(7, CodeFilter.toHtml(author));
            sdbo.setString(8, CodeFilter.toHtml(editor));
            sdbo.setString(9, CodeFilter.toHtml(newsFrom));
            sdbo.setInt(10, top);
            sdbo.setString(11, DateUtil.getNowDate());
            sdbo.executeUpdate();
        }
        catch(Exception sqlE)
        {
            System.out.print("News insNews() " + sqlE.getMessage());
            Debug.writeLog("News insNews(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
        }
        finally
        {
            sdbo.Close();
        }
    }

    public Iterator listNews()
    {
        Vector vector = new Vector();
        if(sdbo == null)
            sdbo = SQLDBOperator.getInstance("Connection");
        String sql = "select newsId,headTitle,DATE_FORMAT(newsTime,'%Y-%m-%d') as time,hits from news where state=1 order by newsTime desc;";
        try
        {
            ResultSet rs = sdbo.executeQuery(sql);
            try
            {
                while(rs.next()) 
                {
                    NEWSTable tableNews = new NEWSTable();
                    tableNews.setNewsId(rs.getInt("newsId"));
                    tableNews.setHeadTitle(rs.getString("headTitle"));
                    tableNews.setNewsTime(rs.getString("time"));
                    tableNews.setHits(rs.getInt("hits"));
                    vector.add(tableNews);
                }
                rs.close();
            }
            catch(NullPointerException nullE)
            {
                System.out.println("News istNews() :" + nullE.getMessage());
                Debug.writeLog("News istNews(), Exception Occured ! Info :" + nullE.getLocalizedMessage());
            }
        }
        catch(SQLException sqlE)
        {
            System.out.println("News istNews() :" + sqlE.getMessage());
            Debug.writeLog("News istNews(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
        }
        finally
        {
            sdbo.Close();
        }
        return vector.iterator();
    }

    public int sumNews()
    {
        if(sdbo == null)
            sdbo = SQLDBOperator.getInstance("Connection");
        int sum = 0;
        String sql = "select count(newsId) as total from news where state=1;";
        try
        {
            ResultSet rs = sdbo.executeQuery(sql);
            try
            {
                rs.next();
                sum = rs.getInt("total");
                rs.close();
            }
            catch(NullPointerException nullE)
            {
                System.out.println("News sumNews() :" + nullE.getMessage());
                Debug.writeLog("News sumNews(), Exception Occured ! Info :" + nullE.getLocalizedMessage());
            }
        }
        catch(SQLException sqlE)
        {
            System.out.println("News sumNews() :" + sqlE.getMessage());
            Debug.writeLog("News sumNews(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
        }
        finally
        {
            sdbo.Close();
        }
        return sum;
    }

    public int sumSearchNews(String search)
    {
        String strSearch = CodeFilter.toHtml(search);
        if(sdbo == null)
            sdbo = SQLDBOperator.getInstance("Connection");
        String sql = "select count(newsId) as total from news where state=1 and headTitle like '%" + strSearch + "%';";
        int total = 0;
        try
        {
            ResultSet rs = sdbo.executeQuery(sql);
            rs.next();
            total = rs.getInt("total");
            rs.close();
        }
        catch(Exception e)
        {
            System.out.print("News sumNews() " + e.getMessage());
            Debug.writeLog("News sumNews(), Exception Occured ! Info :" + e.getLocalizedMessage());
        }
        sdbo.Close();
        return total;
    }

    public Iterator searchNews(String search)
    {
        String strSearch = CodeFilter.toHtml(search);
        Vector vector = new Vector();
        if(sdbo == null)
            sdbo = SQLDBOperator.getInstance("Connection");
        String sql = "select newsId,headTitle,DATE_FORMAT(newsTime,'%Y-%m-%d') as time,hits from news where state=1 and headTitle like '%" + strSearch + "%';";
        try
        {
            ResultSet rs;
            NEWSTable tableNews;
            for(rs = sdbo.executeQuery(sql); rs.next(); vector.add(tableNews))
            {
                tableNews = new NEWSTable();
                tableNews.setNewsId(rs.getInt("newsId"));
                tableNews.setHeadTitle(rs.getString("headTitle"));
                tableNews.setNewsTime(rs.getString("time"));
                tableNews.setHits(rs.getInt("hits"));
            }

            rs.close();
        }
        catch(Exception e)
        {
            System.out.print("News searchNews() " + e.getMessage());
            Debug.writeLog("News searchNews(), Exception Occured ! Info :" + e.getLocalizedMessage());
        }
        sdbo.Close();
        return vector.iterator();
    }

    public Iterator editNews(int newsId)
    {
        Vector vector = new Vector();
        if(sdbo == null)
            sdbo = SQLDBOperator.getInstance("Connection");
        String sql = "select * from news where newsId=?;";
        try
        {
            sdbo.prepareStatement(sql);
            sdbo.setInt(1, newsId);
            ResultSet rs;
            NEWSTable tableNews;
            for(rs = sdbo.executeQuery(); rs.next(); vector.add(tableNews))
            {
                tableNews = new NEWSTable();
                tableNews.setClassId(rs.getInt("classId"));
                tableNews.setKindId(rs.getInt("kindId"));
                tableNews.setMyOther(rs.getInt("myOther"));
                tableNews.setHeadTitle(CodeFilter.unHtml(rs.getString("headTitle")));
                tableNews.setContent(CodeFilter.unHtml(rs.getString("content")));
                tableNews.setConnect(CodeFilter.unHtml(rs.getString("connect")));
                tableNews.setAuthor(rs.getString("author"));
                tableNews.setEditor(rs.getString("editor"));
                tableNews.setNewsFrom(rs.getString("newsFrom"));
                tableNews.setTop(rs.getInt("top"));
            }

            rs.close();
        }
        catch(Exception e)
        {
            System.out.print("News editNews() " + e.getMessage());
            Debug.writeLog("News editNews(), Exception Occured ! Info :" + e.getLocalizedMessage());
        }
        finally
        {
            sdbo.Close();
        }
        return vector.iterator();
    }

    public void upNews(int classId, int kindId, int myOther, String headTitle, String content, String connect, String author, 
            String editor, String newsFrom, int top, int newsId)
    {
        if(sdbo == null)
            sdbo = SQLDBOperator.getInstance("Connection");
        String sql = "update news set classId=?,kindId=?,myOther=?,headTitle=?,content=?,connect=?,author=?,editor=?,newsFrom=?,top=? where newsId=?;";
        try
        {
            sdbo.prepareStatement(sql);
            sdbo.setInt(1, classId);
            sdbo.setInt(2, kindId);
            sdbo.setInt(3, myOther);
            sdbo.setString(4, CodeFilter.toHtml(headTitle));
            sdbo.setString(5, CodeFilter.toHtml(content));
            sdbo.setString(6, CodeFilter.toHtml(connect));
            sdbo.setString(7, CodeFilter.toHtml(author));
            sdbo.setString(8, CodeFilter.toHtml(editor));
            sdbo.setString(9, CodeFilter.toHtml(newsFrom));
            sdbo.setInt(10, top);
            sdbo.setInt(11, newsId);
            sdbo.executeUpdate();
        }
        catch(Exception e)
        {
            System.out.print("News upNews() " + e.getMessage());
            Debug.writeLog("News upNews(), Exception Occured ! Info :" + e.getLocalizedMessage());
        }
        finally
        {
            sdbo.Close();
        }
    }

    public void upUbbNews(int classId, int kindId, int myOther, String headTitle, String content, String connect, String author, 
            String editor, String newsFrom, int top, int newsId)
    {
        if(sdbo == null)
            sdbo = SQLDBOperator.getInstance("Connection");
        String sql = "update news set classId=?,kindId=?,myOther=?,headTitle=?,content=?,connect=?,author=?,editor=?,newsFrom=?,top=? where newsId=?;";
        try
        {
            sdbo.prepareStatement(sql);
            sdbo.setInt(1, classId);
            sdbo.setInt(2, kindId);
            sdbo.setInt(3, myOther);
            sdbo.setString(4, CodeFilter.toHtml(headTitle));
            sdbo.setString(5, CodeFilter.toUbbHtml(content));
            sdbo.setString(6, CodeFilter.toHtml(connect));
            sdbo.setString(7, CodeFilter.toHtml(author));
            sdbo.setString(8, CodeFilter.toHtml(editor));
            sdbo.setString(9, CodeFilter.toHtml(newsFrom));
            sdbo.setInt(10, top);
            sdbo.setInt(11, newsId);
            sdbo.executeUpdate();
        }
        catch(Exception e)
        {
            System.out.print("News upNews() " + e.getMessage());
            Debug.writeLog("News upNews(), Exception Occured ! Info :" + e.getLocalizedMessage());
        }
        finally
        {
            sdbo.Close();
        }
    }

    public void delNews(int newsId)
    {

⌨️ 快捷键说明

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