📄 informbean.java
字号:
package edu.scfc;
import java.sql.*;
import java.util.*;
import java.text.*;
public class InformBean {
private String title = null;
private String content = null;
private String promulgator = null;
private String releaseDept = null;
private String releaseTime = null;
private int browerCount = 0;
private String today = null;
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
ConnDB objConnDB = new ConnDB();
public InformBean() {
}
public void setTitle(String title){
this.title=title;
}
public String getTitle(){
return this.title;
}
public void setContent(String content){
this.content=content;
}
public String getContent(){
return this.content;
}
public void setPromulgator(String promulgator){
this.promulgator=promulgator;
}
public String getPromulgator(){
return this.promulgator;
}
public void setReleaseDept(String releaseDept){
this.releaseDept= releaseDept;
}
public String getReleaseDept(){
return this.releaseDept;
}
public void setReleaseTime(String releasetTime){
this.releaseTime=releasetTime;
}
public String getReleasetTime(){
return this.releaseTime;
}
public void setBrowerCount(int browerCount){
this.browerCount=browerCount;
}
public int getBrowerCount(){
return this.browerCount;
}
public void setToday(String today){
this.today=today;
}
public String getToday(){
return this.today;
}
public Vector selectInformTop6() {
try{
Vector vc = new Vector();
con = objConnDB.getConnection();
pstmt = con.prepareStatement("Select Top 6 * from TB_ReleaseInform order by ReleaseTime DESC");
rs = pstmt.executeQuery();
while(rs.next()){
InformBean objInformBean = new InformBean();
objInformBean.setTitle(rs.getString("Title").trim());
objInformBean.setContent(rs.getString("Content").trim());
objInformBean.setPromulgator(rs.getString("Promulgator").trim());
objInformBean.setReleaseDept(rs.getString("ReleaseDept").trim());
objInformBean.setReleaseTime(rs.getString("ReleaseTime").substring(0,19));
objInformBean.setBrowerCount(rs.getInt("BrowerCount"));
vc.addElement(objInformBean);
}
return vc;
}catch(SQLException ex){}
return null;
}
//查找当前系统的时间(今天)共发布的通知
public ResultSet selectInformToday(){
try{
con = objConnDB.getConnection();
pstmt = con.prepareStatement("select ReleaseTime from TB_ReleaseInform");
rs = pstmt.executeQuery();
}catch(SQLException ex){};
return rs;
}
public int SelectInformID(String title){
try{
int ID=0;
con = objConnDB.getConnection();
pstmt = con.prepareStatement("select ID from TB_ReleaseInform where Title=?");
pstmt.setString(1,title);
rs = pstmt.executeQuery();
if(rs.next()){
ID =rs.getInt("ID");
}
return ID;
}catch(SQLException ex){}
return 0;
}
public int insertInform(String title,String content,String promulgator,String releaseDept,String releaseTime){
java.text.SimpleDateFormat releaseTime1 = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Timestamp Timestamp = null;
try {
Timestamp = new Timestamp(releaseTime1.parse(releaseTime).getTime());
} catch (ParseException ex1) {
}
try{
con = objConnDB.getConnection();
pstmt = con.prepareStatement("insert into TB_ReleaseInform(Title,Content,Promulgator,ReleaseDept,ReleaseTime)values(?,?,?,?,?)");
pstmt.setString(1,title);
pstmt.setString(2,content);
pstmt.setString(3,promulgator);
pstmt.setString(4,releaseDept);
pstmt.setTimestamp(5,Timestamp);
int i = pstmt.executeUpdate();
return i;
}catch(SQLException ex){}
return 0;
}
public int updateInform(String title,String content,String promulgator,String releaseDept,String releaseTime,int id){
java.text.SimpleDateFormat releaseTime1 = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Timestamp Timestamp = null;
try {
Timestamp = new Timestamp(releaseTime1.parse(releaseTime).getTime());
} catch (ParseException ex1) {
}
try{
con = objConnDB.getConnection();
pstmt = con.prepareStatement("update TB_ReleaseInform set Title=?,Content=?,Promulgator=?,ReleaseDept=?,ReleaseTime=? where ID=?");
pstmt.setString(1,title);
pstmt.setString(2,content);
pstmt.setString(3,promulgator);
pstmt.setString(4,releaseDept);
pstmt.setTimestamp(5,Timestamp);
pstmt.setInt(6,id);
int i = pstmt.executeUpdate();
return i;
}catch(SQLException ex){ex.printStackTrace();}
return 0;
}
public int DeleteInformID(int id){
try{
con = objConnDB.getConnection();
pstmt=con.prepareStatement("Delete from TB_ReleaseInform where ID=?");
pstmt.setInt(1,id);
int i = pstmt.executeUpdate();
return i;
}catch(SQLException ex){
ex.printStackTrace();
}
return 0;
}
public int CloseStatu(int id){
try{
String statu = "关闭";
con = objConnDB.getConnection();
pstmt=con.prepareStatement("update TB_ReleaseInform set Statu=? where ID=?");
pstmt.setString(1,statu);
pstmt.setInt(2,id);
int i = pstmt.executeUpdate();
return i;
}catch(SQLException ex){
ex.printStackTrace();
}
return 0;
}
public int OpenStatu(int id){
try{
String statu = "开启";
con = objConnDB.getConnection();
pstmt=con.prepareStatement("update TB_ReleaseInform set Statu=? where ID=?");
pstmt.setString(1,statu);
pstmt.setInt(2,id);
int i = pstmt.executeUpdate();
return i;
}catch(SQLException ex){
ex.printStackTrace();
}
return 0;
}
public void UpdateBrower(int id){
try{
con = objConnDB.getConnection();
pstmt = con.prepareStatement("update TB_ReleaseInform set BrowerCount=BrowerCount+1 where ID=?");
pstmt.setInt(1,id);
pstmt.executeUpdate();
}catch(SQLException ex){
ex.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -