【Java开源代码栏目提醒】:以下是网学会员为您推荐的Java开源代码-articles.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(Us