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

📄 news.java

📁 动态网站管理发布系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        if(sdbo == null)
            sdbo = SQLDBOperator.getInstance("Connection");
        String sql = "delete from news where newsId=?;";
        try
        {
            sdbo.prepareStatement(sql);
            sdbo.setInt(1, newsId);
            sdbo.executeUpdate();
        }
        catch(Exception e)
        {
            System.out.print("News delNews() " + e.getMessage());
            Debug.writeLog("News delNews(), Exception Occured ! Info :" + e.getLocalizedMessage());
        }
        finally
        {
            sdbo.Close();
        }
    }

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

    public int sumShNews()
    {
        if(sdbo == null)
            sdbo = SQLDBOperator.getInstance("Connection");
        int sum = 0;
        String sql = "select count(newsId) as total from news where state=0;";
        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 void shNews(int newsId)
    {
        if(sdbo == null)
            sdbo = SQLDBOperator.getInstance("Connection");
        String strSql = "update news set state=1 where newsId='" + newsId + "'";
        try
        {
            sdbo.executeUpdate(strSql);
        }
        catch(Exception e)
        {
            System.out.print("News listShNews() " + e.getMessage());
            Debug.writeLog("News listShNews(), Exception Occured ! Info :" + e.getLocalizedMessage());
        }
        finally
        {
            sdbo.Close();
        }
    }

    public boolean isTalk()
    {
        ResultSet rs = null;
        String strSql = "select replyId from newsreply";
        boolean isTalk = false;
        if(sdbo == null)
            sdbo = SQLDBOperator.getInstance("Connection");
        try
        {
            rs = sdbo.executeQuery(strSql);
            try
            {
                rs.last();
                if(rs.getRow() > 0)
                    isTalk = true;
                rs.close();
            }
            catch(NullPointerException nullE)
            {
                System.out.print("News isTalk() " + nullE.getMessage());
                Debug.writeLog("News isTalk(), Exception Occured ! Info :" + nullE.getLocalizedMessage());
            }
        }
        catch(SQLException sqlE)
        {
            System.out.print("Usr isAdminName() " + sqlE.getMessage());
            Debug.writeLog("Usr isAdminName(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
        }
        finally
        {
            sdbo.Close();
        }
        return isTalk;
    }

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

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

    public int sumReply(int newsId)
    {
        ResultSet rs = null;
        int sum = 0;
        String strSql = "select count(replyId) as total from newsreply where newsId=?;";
        if(sdbo == null)
            sdbo = SQLDBOperator.getInstance("Connection");
        try
        {
            sdbo.prepareStatement(strSql);
            sdbo.setInt(1, newsId);
            rs = sdbo.executeQuery();
            try
            {
                rs.next();
                sum = rs.getInt("total");
                rs.close();
            }
            catch(NullPointerException nullE)
            {
                System.out.print("Usr isAdminName() " + nullE.getMessage());
                Debug.writeLog("Usr isAdminName(), Exception Occured ! Info :" + nullE.getLocalizedMessage());
            }
        }
        catch(SQLException sqlE)
        {
            System.out.print("Usr isAdminName() " + sqlE.getMessage());
            Debug.writeLog("Usr isAdminName(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
        }
        finally
        {
            sdbo.Close();
        }
        return sum;
    }

    public Iterator listReply(int newsId)
    {
        ResultSet rs;
        String strSql;
        Vector vector;
        rs = null;
        strSql = "select replyId,newsId,user,content from newsreply where newsId=?;";
        vector = new Vector();
        if(sdbo == null)sdbo = SQLDBOperator.getInstance("Connection");
        try
        {
            sdbo.prepareStatement(strSql);
            sdbo.setInt(1, newsId);
            rs = sdbo.executeQuery();
            try
            {
                while(rs.next()) 
                {
                    NEWSReply tableReply = new NEWSReply();
                    tableReply.setReplyId(rs.getInt("replyId"));
                    tableReply.setUser(rs.getString("user"));
                    tableReply.setContent(rs.getString("content"));
                    vector.add(tableReply);
                }
            }
            catch(NullPointerException nullE)
            {
                System.out.print("News listReplyNews() " + nullE.getMessage());
                Debug.writeLog("News listReplyNews(), Exception Occured ! Info :" + nullE.getLocalizedMessage());
            }
        }catch(SQLException e){
        	e.printStackTrace();
        }
        finally
        {
            sdbo.Close();
        }

        return vector.iterator();
    }

    public void delNewsReply(int replyId)
    {
        if(sdbo == null)
            sdbo = SQLDBOperator.getInstance("Connection");
        String strSql = "delete from NEWSReply where replyId=?;";
        try
        {
            sdbo.prepareStatement(strSql);
            sdbo.setInt(1, replyId);
            sdbo.executeUpdate();
        }
        catch(Exception e)
        {
            System.out.print("News listShNews() " + e.getMessage());
            Debug.writeLog("News listShNews(), Exception Occured ! Info :" + e.getLocalizedMessage());
        }
        finally
        {
            sdbo.Close();
        }
    }
}

⌨️ 快捷键说明

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