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

📄 newsshow.java

📁 本系统分两部分管理,前台用于文章发布和用户文章发表,后台有管理员审核和不同权限的用户管理,具有高稳定性和安全性。整个站的全部数据逻辑运算完全有beans封装, 具有界面简洁、功能强大、操作方便等特点。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.ntsky.news;
/**
 * <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.sql.*;
import java.util.*;

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

public class NewsShow {
    private SQLDBOperator sdbo=null;
    /**
     * 本站发表的文章总数
     */
    public int sumNews(){
        int sum=0;
        if (sdbo==null)
            sdbo = SQLDBOperator.getInstance("Connection");
        ResultSet rs=null;
        String strSql = "select count(newsId) as total from news where state=1;";
        try{
            rs = sdbo.executeQuery(strSql);
            try{
                rs.next();
                sum=rs.getInt("total");
                rs.close();
            }
            catch(NullPointerException nullE){
                System.out.print("NewsShow sumNews() " +nullE.getMessage());
                Debug.writeLog("NewsShow sumNews(), Exception Occured ! Info :" + nullE.getLocalizedMessage());
            }
        }
        catch(SQLException sqlE){
            System.out.print("NewsShow sumNews() " +sqlE.getMessage());
            Debug.writeLog("NewsShow sumNews(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
        }
        finally{
            sdbo.Close();
        }
        return sum;
    }
    /**
     * 本站注册的用户总数
     */
    public int sumUser(){
        int sum=0;
        if (sdbo==null)
            sdbo = SQLDBOperator.getInstance("Connection");
        ResultSet rs=null;
        String strSql = "select count(userName) as total from newsusr;";
        try{
            rs = sdbo.executeQuery(strSql);
            try{
                rs.next();
                sum = rs.getInt("total");
                rs.close();
            }
            catch(NullPointerException nullE){
                System.out.print("NewsShow sumUser() " +nullE.getMessage());
                Debug.writeLog("NewsShow sumUser(), Exception Occured ! Info :" + nullE.getLocalizedMessage());
            }
        }
        catch(SQLException sqlE){
            System.out.print("NewsShow sumUser() " +sqlE.getMessage());
            Debug.writeLog("NewsShow sumUser(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
        }
        finally{
            sdbo.Close();
        }
        return sum;
    }
    /**
     * 网站最近更新的时间
     */
    //判断初始有无值
    public boolean isTime(){
        ResultSet rs=null;
        if (sdbo==null)
            sdbo = SQLDBOperator.getInstance("Connection");
        boolean isTime=false;
        String strSql = "select newsId from news where state=1;";
        try{
            rs = sdbo.executeQuery(strSql);
            try{
                rs.last();
                if(rs.getRow()>0){
                    isTime=true;
                }
                rs.close();
            }
            catch(NullPointerException nullE){
                System.out.print("NewsShow isTime() " +nullE.getMessage());
                Debug.writeLog("NewsShow isTime(), Exception Occured ! Info :" + nullE.getLocalizedMessage());
            }
        }
        catch(SQLException sqlE){
            System.out.print("NewsShow isTime() " +sqlE.getMessage());
            Debug.writeLog("NewsShow isTime(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
        }
        finally{
            sdbo.Close();
        }
        return isTime;
    }
    //取得具体的时间
    public String lastTime(){
        if (sdbo==null)
            sdbo = SQLDBOperator.getInstance("Connection");
        ResultSet rs=null;
        String newsTime = null;
        String strSql = "select newsTime from news where state=1 order by newsTime desc;";
        try{
            rs = sdbo.executeQuery(strSql);
            try{
                rs.next();
                newsTime=rs.getString("newsTime");
            }
            catch(NullPointerException nullE){
                System.out.print("NewsShow lastTime() " +nullE.getMessage());
                Debug.writeLog("NewsShow lastTime(), Exception Occured ! Info :" + nullE.getLocalizedMessage());
            }
        }
        catch(SQLException sqlE){
            System.out.print("NewsShow lastTime() " +sqlE.getMessage());
            Debug.writeLog("NewsShow lastTime(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
        }
        finally{
            sdbo.Close();
        }
        return newsTime;
    }
    /**
     * 判断有无的文章
     */
    public boolean isNews(){
        boolean isNews=false;
        if (sdbo==null)
            sdbo = SQLDBOperator.getInstance("Connection");
        ResultSet rs=null;
        String strSql = "select newsId from news where state=1;";
        try{
            rs = sdbo.executeQuery(strSql);
            try{
                rs.last();
                if(rs.getRow()>0){
                    isNews=true;
                }
                rs.close();
            }
            catch(NullPointerException nullE){
                System.out.print("NewsShow isTopNews() " +nullE.getMessage());
                Debug.writeLog("NewsShow isTopNews(), Exception Occured ! Info :" + nullE.getLocalizedMessage());
            }
        }
        catch(SQLException sqlE){
            System.out.print("NewsShow isTopNews() " +sqlE.getMessage());
            Debug.writeLog("NewsShow isTopNews(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
        }
        finally{
            sdbo.Close();
        }
        return isNews;
    }
    /**
     * 判断有无前缀的文章
     * @return
     */
    public boolean isTopNews(){
        if (sdbo==null)
            sdbo = SQLDBOperator.getInstance("Connection");
        boolean isTopNews=false;
        ResultSet rs=null;
        String strSql = "select newsId from news where state=1 and top=1;";
        try{
            rs = sdbo.executeQuery(strSql);
            try{
                rs.last();
                if(rs.getRow()>0){
                    isTopNews=true;
                }
                rs.close();
            }
            catch(NullPointerException nullE){
                System.out.print("NewsShow isTopNews() " +nullE.getMessage());
                Debug.writeLog("NewsShow isTopNews(), Exception Occured ! Info :" + nullE.getLocalizedMessage());
            }
        }
        catch(SQLException sqlE){
            System.out.print("NewsShow isTopNews() " +sqlE.getMessage());
            Debug.writeLog("NewsShow isTopNews(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
        }
        finally{
            sdbo.Close();
        }
        return isTopNews;
    }
    /**
     * 最新的记录(前缀)
     */
    public Iterator topNews(){
        ResultSet rs=null;
        if (sdbo==null)
            sdbo = SQLDBOperator.getInstance("Connection");
        Vector vector=new Vector();
        String strSql = "select newsId,classId,headTitle from news where state=1 and top=1 order by newsTime desc limit 0,1;";
        try{
            rs = sdbo.executeQuery(strSql);
            try{
                while(rs.next()){
                    NEWSTable tableNews = new NEWSTable();
                    tableNews.setNewsId(rs.getInt("newsId"));
                    tableNews.setClassId(rs.getInt("classId"));
                    tableNews.setHeadTitle(rs.getString("headTitle"));
                    vector.add(tableNews);
                }
                rs.close();
            }
            catch(NullPointerException nullE){
                System.out.print("NewsShow topNews() " +nullE.getMessage());
                Debug.writeLog("NewsShow topNews(), Exception Occured ! Info :" + nullE.getLocalizedMessage());
            }
        }
        catch(SQLException sqlE){
            System.out.print("NewsShow topNews() " +sqlE.getMessage());
            Debug.writeLog("NewsShow topNews(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
        }
        finally{
            sdbo.Close();
        }
        return vector.iterator();
    }
    /**
     *   判断最新的文章(不用前缀)
     */
    public boolean isNewNews(){
        ResultSet rs=null;
        if (sdbo==null)
            sdbo = SQLDBOperator.getInstance("Connection");
        boolean isNewNews=false;
        Vector vector=new Vector();
        String strSql = "select newsId from news where state=1 and top=0;";
        try{
            rs = sdbo.executeQuery(strSql);
            try{
                rs.last();
                if(rs.getRow()>0){
                    isNewNews=true;
                }
                rs.close();

⌨️ 快捷键说明

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