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

📄 articles.java

📁 2.打开“命令行提示符”; 3.输入mysql –u root - p命令
💻 JAVA
字号:
package com.ch9;

import java.sql.*;

public class articles extends Execute_DB
{
	//定义类成员变量
	private long ArticleID;
	private String ArticleTitle;
	private String ArticleContent; 
	private long UserID;  
	private long BoardID;   
	private long FatherID; 
	private int Sign;
	private int ReadCount; 
	private int ReCount;    
	private int GoodArticle;
	private String PicUrl;
	private String PicName;
	private String CreateTime;   
	private String strSql;
   
    //构造函数,对成员变量进行初始化赋值
	public articles()
	{       
		this.ArticleID=0;
		this.ArticleTitle="";
		this.ArticleContent="";        
		this.GoodArticle=0;
		this.BoardID=0;
		this.Sign=0;
		this.ReCount=0;
		this.ReadCount=0;       
		this.PicUrl="";
		this.PicName="";
		this.FatherID=0;
		this.UserID=0;                      
		java.util.Date NowTime = new java.util.Date();
		this.CreateTime = NowTime.toLocaleString();                    
		this.strSql="";
	}
   
	//添加新文章,往articles数据表中添加一条新记录
	public boolean add_article()
	{	
		this.strSql="insert into articles ";
		this.strSql=this.strSql + "(";
		this.strSql=this.strSql + "ArticleTitle,ArticleContent,UserID,BoardID,FatherID,Sign,ReadCount,ReCount,GoodArticle,PicUrl,PicName,CreateTime) ";		
		this.strSql=this.strSql + "values('" + this.ArticleTitle + "','" + this.ArticleContent + "','" + this.UserID + "','" + this.BoardID + "','" + this.FatherID + "','" + this.Sign + "','" + this.ReadCount + "','" + this.ReCount + "','" + this.GoodArticle + "','" + this.PicUrl + "','" + this.PicName + "','" + this.CreateTime + "')";		
		boolean isAdd = super.exeSql(this.strSql);
		
		return isAdd;
	}
  
  	//删除ArticleID对应的文章的信息
	public boolean delete()
	{
		this.strSql="delete from `articles` where ArticleID='";
		this.strSql=this.strSql + this.ArticleID + "'";
		boolean isDelete = super.exeSql(this.strSql);
        
		return isDelete;
	}
   
  	//获取ArticleID对应的文章的信息,将这些信息赋值给相应的类变量
	public boolean  init()
	{
    	this.strSql="select * from `articles` where ArticleID=";
        this.strSql=this.strSql + "'" + this.ArticleID + "'";        
        try
		{
   			ResultSet rs = super.exeSqlQuery(this.strSql);
			if (rs.next())
			{
                ArticleID=rs.getLong("ArticleID");
                ArticleTitle=rs.getString("ArticleTitle");
                ArticleContent=rs.getString("ArticleContent");
                GoodArticle=rs.getInt("GoodArticle");
                BoardID=rs.getLong("BoardID");
                FatherID=rs.getLong("FatherID");
                Sign=rs.getInt("Sign");
                ReadCount=rs.getInt("ReadCount");
                UserID=rs.getLong("UserID"); 
                ReCount=rs.getInt("ReCount");
                PicUrl=rs.getString("PicUrl");
                PicName=rs.getString("PicName");
                CreateTime=rs.getString("CreateTime");
                return true;
			}
			else
			{
				return false;
			}
		}
		catch(Exception ex)
		{
			return false;
		}        
	}

	//获得FatherID相同的一组文章的信息,返回一个ResultSet类型对象
	public ResultSet show_son_articles()
	{	
		this.strSql="select * from `articles`";
        this.strSql=this.strSql + " where FatherID = '" + this.FatherID + "'";        
		ResultSet rs = null;              
		try
		{
			rs = super.exeSqlQuery(this.strSql); 
		}
		catch(Exception ex)
		{
			System.out.println(ex.toString()); 
		}
		return rs;	    
	}

  	//获得BoardID对应的讨论区的所有主贴的文章信息,返回一个ResultSet类型对象
	public ResultSet show_board_articles()
	{	
		this.strSql="select ArticleID,ArticleTitle,UserID,ReadCount,ReCount,CreateTime from `articles`";
        this.strSql=this.strSql + " where BoardID = '" + this.BoardID + "'";        
        this.strSql=this.strSql + " and FatherID = '0' order by CreateTime desc";
		ResultSet rs = null;              
		try
		{
			rs = super.exeSqlQuery(this.strSql); 
		}
		catch(Exception ex)
		{
			System.out.println(ex.toString()); 
		}
		return rs;	    
	}
	
	//获得BoardID对应的讨论区的所有精华文章信息,返回一个ResultSet类型对象
	public ResultSet show_board_good_articles()
	{	
		this.strSql="select ArticleID,ArticleTitle,UserID,CreateTime from articles";
        this.strSql=this.strSql + " where BoardID = '" + this.BoardID + "'";        
        this.strSql=this.strSql + " and GoodArticle = '1' order by CreateTime desc";
		ResultSet rs = null;              
		try
		{
			rs = super.exeSqlQuery(this.strSql); 
		}
		catch(Exception ex)
		{
			System.out.println(ex.toString()); 
		}
		return rs;	    
	}

	
	//根据查询条件获得文章查询结果
	public ResultSet search_articles(long UserID,String ArticleTitle1,String ArticleTitle2,String ArticleTitle3,int Days)
	{	
		this.strSql = "select * from articles where ";
		if(UserID != 0)
		{
			this.strSql=this.strSql + " UserID = '" + UserID + "' and ";			 
		}
		
		this.strSql=this.strSql + " (ArticleTitle like '%"+ ArticleTitle1 +"%"+ArticleTitle2+"%' or ArticleTitle like '%"+ ArticleTitle2 +"%"+ArticleTitle1+"%')"; 
		
		if(ArticleTitle3 != null && ArticleTitle3 != "")
		{
			this.strSql=this.strSql + "and ArticleTitle not like '%"+ ArticleTitle3 +"%' ";
		}
		
		java.util.Date NowTime = new java.util.Date();
		long l_SearchTime = NowTime.getTime() - Days*24*60*60*1000;
		NowTime.setTime(l_SearchTime);
		String s_SearchTime = NowTime.toLocaleString();
		this.strSql=this.strSql + " and CreateTime > '"+s_SearchTime+"' and FatherID = '0' order by BoardID,CreateTime desc";

		System.out.println(this.strSql); 
		ResultSet rs = null;              
		try
		{
			rs = super.exeSqlQuery(this.strSql); 
		}
		catch(Exception ex)
		{
			System.out.println(ex.toString()); 
		}
		return rs;	    
	}
	
	
	//获得BoardID对应的讨论区的所有主贴的数量
	public int board_articles_count()
	{	
		this.strSql="select ArticleID,ArticleTitle,UserID,ReadCount,ReCount,CreateTime from `articles`";
        this.strSql=this.strSql + " where BoardID = '" + this.BoardID + "'";        
        this.strSql=this.strSql + " and FatherID = '0'";
        ResultSet rs = null; 
		try
		{
			rs = super.exeSqlQuery(this.strSql);
			rs.last();
			return rs.getRow();	
		}
		catch(Exception ex)
		{
			System.out.println(ex.toString()); 
			return 0;
		}  
	}
	
	//修改类成员变量GoodArticle的值
	public boolean modify_GoodArticle()
	{
		this.strSql="update articles set";
		this.strSql=this.strSql + " GoodArticle = '1'";	
		this.strSql=this.strSql + " where ArticleID='" + this.ArticleID + "'";
		boolean isModify = super.exeSql(this.strSql);
		
		return isModify;
	}
	
	//更改articles数据表中ReadCount的值
	public boolean modify_ReadCount()
	{
		this.strSql="update articles set";
		this.strSql=this.strSql + " ReadCount = '"+this.ReadCount+"'";	
		this.strSql=this.strSql + " where ArticleID='" + this.ArticleID + "'";
		boolean isModify = super.exeSql(this.strSql);
		
		return isModify;
	}
	
	//更改articles数据表中ReCount的值
	public boolean modify_ReCount()
	{
		this.strSql="update articles set";
		this.strSql=this.strSql + " ReCount = '"+this.ReCount+"'";	
		this.strSql=this.strSql + " where ArticleID='" + this.ArticleID + "'";
		boolean isModify = super.exeSql(this.strSql);
		
		return isModify;
	}


  	//设置类成员变量ArticleID的值
	public void setArticleID(long ArticleID)
	{
		this.ArticleID = ArticleID;	
	}
   
	//获取类成员变量ArticleID的值  
	public long getArticleID()
	{
		return this.ArticleID;	
	}

	//设置类成员变量ArticleTitle的值
 	public void setArticleTitle(String ArticleTitle)
	{
		this.ArticleTitle = ArticleTitle;	
	}
   
	//获取类成员变量ArticleTitle的值  
	public String getArticleTitle()
	{
		return this.ArticleTitle;	
	}

	//设置类成员变量ArticleContent的值  
 	public void setArticleContent(String ArticleContent)
	{
		this.ArticleContent = ArticleContent;	
	}
   
	//获取类成员变量ArticleContent的值  
	public String getArticleContent()
	{
		return this.ArticleContent;	
	}

	//设置类成员变量UserID的值 
	public void setUserID(long UserID)
	{
		this.UserID = UserID;	
	}

	//获取类成员变量UserID的值  
	public long getUserID()
	{
		return this.UserID;	
	}

	//设置类成员变量BoardID的值  
 	public void setBoardID(long BoardID)
	{
		this.BoardID = BoardID;	
	}
   
	//获取类成员变量BoardID的值  
	public long getBoardID()
	{
		return this.BoardID;	
	}

	//设置类成员变量FatherID的值  
 	public void setFatherID(long FatherID)
	{
		this.FatherID = FatherID;	
	}
   
	//获取类成员变量FatherID的值  
	public long getFatherID()
	{
		return this.FatherID;	
	}

	//设置类成员变量Sign的值  
 	public void setSign(int Sign)
	{
		this.Sign = Sign;	
	}
   
	//获取类成员变量Sign的值  
	public int getSign()
	{
		return this.Sign;	
	}
 
 	//设置类成员变量CreateTime的值 
 	public void setCreateTime(String CreateTime)
	{
		this.CreateTime = CreateTime;	
	}   

	//获取类成员变量CreateTime的值  
	public String getCreateTime()
	{
		return this.CreateTime;	
	}  

	//设置类成员变量ReadCount的值 
	public void setReadCount(int ReadCount)
	{
		this.ReadCount = ReadCount;	
	}

	//获取类成员变量ReadCount的值  
	public int getReadCount()
	{
		return this.ReadCount;	
	}

	//设置类成员变量ReCount的值  
 	public void setReCount(int ReCount)
	{
		this.ReCount = ReCount;	
	}
   
	//获取类成员变量ReCount的值  
	public int getReCount()
	{
		return this.ReCount;	
	}

	//设置类成员变量GoodArticle的值  
 	public void setGoodArticle(int GoodArticle)
	{
		this.GoodArticle = GoodArticle;	
	}
   
	//获取类成员变量GoodArticle的值  
	public int getGoodArticle()
	{
		return this.GoodArticle;	
	}
 
 	//设置类成员变量PicUrl的值 
 	public void setPicUrl(String PicUrl)
	{
		this.PicUrl = PicUrl;	
	}   

	//获取类成员变量PicUrl的值  
	public String getPicUrl()
	{
		return this.PicUrl;	
	}  
	
	//设置类成员变量PicName的值 
 	public void setPicName(String PicName)
	{
		this.PicName = PicName;	
	}   

	//获取类成员变量PicName的值  
	public String getPicName()
	{
		return this.PicName;	
	}  	
}

⌨️ 快捷键说明

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