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

📄 notice.java

📁 jsp动态网站开发技术与实践 电子工业出版社 随书附赠源代码
💻 JAVA
字号:
package com.chapter15;

import java.sql.*;

public class Notice extends ExecuteDB
{
	//定义类成员变量
	private long NoticeID;
	private String Subject;
	private String Content; 
	private long UserID;  
	private String Attachment;
	private String FileUrl;
	private String CreateTime;   
	private String strSql;
   
	//构造函数,对成员变量进行初始化赋值
	public Notice()
	{       
		this.NoticeID=0;
		this.Subject="";
		this.Content="";        
		this.Attachment="";
		this.FileUrl="";
		this.UserID=0;                      
		java.util.Date NowTime = new java.util.Date();
		this.CreateTime = NowTime.toLocaleString();                    
		this.strSql="";
	}
   
	//添加新公告,往notices数据表中添加一条新记录
	public boolean add()
	{	
		this.strSql="insert into notices ";
		this.strSql=this.strSql + "(Subject,Content,UserID,Attachment,FileUrl,CreateTime)";		
		this.strSql=this.strSql + "values('" + this.Subject + "','" + this.Content + "','" + this.UserID + "','" + this.Attachment + "','" + this.FileUrl + "','" + this.CreateTime + "')";		
	
		boolean isAdd = super.exeSql(this.strSql);
		return isAdd;
	}
	
	//修改NoticeID对应的公告信息
	public boolean modify()
	{
		this.strSql="update notices set";
		this.strSql=this.strSql + " Subject=" + "'" + this.Subject + "',";
		this.strSql=this.strSql + " Content=" + "'" + this.Content + "',";
		this.strSql=this.strSql + " UserID=" + "'" + this.UserID + "',";
		this.strSql=this.strSql + " Attachment=" + "'" + this.Attachment + "',";
		this.strSql=this.strSql + " FileUrl=" + "'" + this.FileUrl + "',";
		this.strSql=this.strSql + " CreateTime=" + "'" + this.CreateTime + "'";
		this.strSql=this.strSql + " where UserID='" + this.UserID + "'";
		
		boolean isUpdate = super.exeSql(this.strSql);		
		return isUpdate;
	}
  
	//删除sNoticeID中对应的公告信息
	public boolean delete(String sNoticeID)
	{
		this.strSql="delete from notices";
		this.strSql=this.strSql + "  where NoticeID in ("+sNoticeID+")";
		
		boolean isDelete = super.exeSql(this.strSql);      
		return isDelete;	
	}

	//获取NoticeID对应的公告的信息,将这些信息赋值给相应的类变量
	public boolean init()
	{
		this.strSql="select * from `notices` where NoticeID=";
		this.strSql=this.strSql + "'" + this.NoticeID + "'";        
		try
		{
   			ResultSet rs = super.exeQuery(this.strSql);
			if (rs.next())
			{
                NoticeID=rs.getLong("NoticeID");
                Subject=rs.getString("Subject");
                Content=rs.getString("Content");
                UserID=rs.getLong("UserID"); 
                Attachment=rs.getString("Attachment");
                FileUrl=rs.getString("FileUrl");
                CreateTime=rs.getString("CreateTime");
                return true;
			}
			else
			{
				return false;
			}
		}
		catch(Exception ex)
		{
			return false;
		}        
	}

	//获得所有公告信息,返回一个ResultSet类型对象
	public ResultSet show_notices()
	{	
		this.strSql="select * from `notices` order by CreateTime desc";
		ResultSet rs = null;              
		try
		{
			rs = super.exeQuery(this.strSql); 
		}
		catch(Exception e)
		{
			System.out.println(e.toString()); 
		}
		return rs;	    
	}

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

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

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

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

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

 	//设置类成员变量CreateTime的值 
 	public void setCreateTime(String CreateTime)
	{
		this.CreateTime = CreateTime;	
	}   

	//获取类成员变量CreateTime的值  
	public String getCreateTime()
	{
		return this.CreateTime;	
	}  
 
 	//设置类成员变量Attachment的值 
 	public void setAttachment(String Attachment)
	{
		this.Attachment = Attachment;	
	}   

	//获取类成员变量Attachment的值  
	public String getAttachment()
	{
		return this.Attachment;	
	}  
	
	//设置类成员变量FileUrl的值 
 	public void setFileUrl(String FileUrl)
	{
		this.FileUrl = FileUrl;	
	}   

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

⌨️ 快捷键说明

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