📄 news.java
字号:
package com.ntsky.news.manage;
/**
* <p>Title: NTsky新闻发布v1.0正式版</p>
* <p>Description: 新闻管理</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: NTsky</p>
* @authory 姚君林
* @version 1.0
*/
import java.io.*;
import java.sql.*;
import java.util.*;
import com.ntsky.common.*;
import com.ntsky.database.*;
import com.ntsky.persistence.*;
public class News {
private SQLDBOperator sdbo=null;
/**
* 插入数据
*/
public void insNews(int classId,int kindId,int myOther,String headTitle,String content,String connect,String author,String editor,String newsFrom,int top){
if (sdbo==null)
sdbo = SQLDBOperator.getInstance("Connection");
String sql = "insert into news(classId,kindId,myOther,headTitle,content,connect,author,editor,newsFrom,top,newsTime,state,tag) values(?,?,?,?,?,?,?,?,?,?,?,1,1);";
try{
sdbo.prepareStatement(sql);
sdbo.setInt(1,classId);
sdbo.setInt(2,kindId);
sdbo.setInt(3,myOther);
sdbo.setString(4,CodeFilter.toHtml(headTitle));
sdbo.setString(5,CodeFilter.toHtml(content));
sdbo.setString(6,CodeFilter.toHtml(connect));
sdbo.setString(7,CodeFilter.toHtml(author));
sdbo.setString(8,CodeFilter.toHtml(editor));
sdbo.setString(9,CodeFilter.toHtml(newsFrom));
sdbo.setInt(10,top);
sdbo.setString(11,DateUtil.getNowDate());
sdbo.executeUpdate();
}
catch(Exception sqlE){
System.out.print("News insNews() " +sqlE.getMessage());
Debug.writeLog("News insNews(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
}
finally{
sdbo.Close();
}
}
/**
* 插入数据
*/
public void insUbbNews(int classId,int kindId,int myOther,String headTitle,String content,String connect,String author,String editor,String newsFrom,int top){
if (sdbo==null)
sdbo = SQLDBOperator.getInstance("Connection");
String sql = "insert into news(classId,kindId,myOther,headTitle,content,connect,author,editor,newsFrom,top,newsTime,state,tag) values(?,?,?,?,?,?,?,?,?,?,?,1,1);";
try{
sdbo.prepareStatement(sql);
sdbo.setInt(1,classId);
sdbo.setInt(2,kindId);
sdbo.setInt(3,myOther);
sdbo.setString(4,CodeFilter.toHtml(headTitle));
sdbo.setString(5,CodeFilter.toUbbHtml(content));
sdbo.setString(6,CodeFilter.toHtml(connect));
sdbo.setString(7,CodeFilter.toHtml(author));
sdbo.setString(8,CodeFilter.toHtml(editor));
sdbo.setString(9,CodeFilter.toHtml(newsFrom));
sdbo.setInt(10,top);
sdbo.setString(11,DateUtil.getNowDate());
sdbo.executeUpdate();
}
catch(Exception sqlE){
System.out.print("News insNews() " +sqlE.getMessage());
Debug.writeLog("News insNews(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
}
finally{
sdbo.Close();
}
}
/**
* 列出文章
*/
public Iterator listNews(){
Vector vector=new Vector();
if (sdbo==null)
sdbo = SQLDBOperator.getInstance("Connection");
String sql = "select newsId,headTitle,DATE_FORMAT(newsTime,'%Y-%m-%d') as time,hits from news where state=1 order by newsTime desc;";
try{
ResultSet rs = sdbo.executeQuery(sql);
try{
while (rs.next()) {
NEWSTable tableNews = new NEWSTable();
tableNews.setNewsId(rs.getInt("newsId"));
tableNews.setHeadTitle(rs.getString("headTitle"));
tableNews.setNewsTime(rs.getString("time"));
tableNews.setHits(rs.getInt("hits"));
vector.add(tableNews);
}
rs.close();
}
catch(NullPointerException nullE){
System.out.println("News istNews() :" +nullE.getMessage());
Debug.writeLog("News istNews(), Exception Occured ! Info :" + nullE.getLocalizedMessage());
}
}
catch(SQLException sqlE){
System.out.println("News istNews() :" +sqlE.getMessage());
Debug.writeLog("News istNews(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
}
finally{
sdbo.Close();
}
return vector.iterator();
}
/**
* 已经发布的新闻总记录
*/
public int sumNews(){
if (sdbo==null)
sdbo = SQLDBOperator.getInstance("Connection");
int sum=0;
String sql="select count(newsId) as total from news where state=1;";
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 int sumSearchNews(String search){
String strSearch = CodeFilter.toHtml(search);
if (sdbo==null)
sdbo = SQLDBOperator.getInstance("Connection");
String sql = "select count(newsId) as total from news where state=1 and headTitle like '%" + strSearch + "%';";
int total=0;
try{
ResultSet rs = sdbo.executeQuery(sql);
rs.next();
total=rs.getInt("total");
rs.close();
}
catch(Exception e){
System.out.print("News sumNews() " +e.getMessage());
Debug.writeLog("News sumNews(), Exception Occured ! Info :" + e.getLocalizedMessage());
}
sdbo.Close();
return total;
}
//列出搜索的结果
public Iterator searchNews(String search){
String strSearch=CodeFilter.toHtml(search);
Vector vector=new Vector();
if (sdbo==null)
sdbo = SQLDBOperator.getInstance("Connection");
String sql = "select newsId,headTitle,DATE_FORMAT(newsTime,'%Y-%m-%d') as time,hits from news where state=1 and headTitle like '%"+strSearch+"%';";
try{
ResultSet rs=sdbo.executeQuery(sql);
while(rs.next()){
NEWSTable tableNews=new NEWSTable();
tableNews.setNewsId(rs.getInt("newsId"));
tableNews.setHeadTitle(rs.getString("headTitle"));
tableNews.setNewsTime(rs.getString("time"));
tableNews.setHits(rs.getInt("hits"));
vector.add(tableNews);
}
rs.close();
}
catch(Exception e){
System.out.print("News searchNews() " +e.getMessage());
Debug.writeLog("News searchNews(), Exception Occured ! Info :" + e.getLocalizedMessage());
}
sdbo.Close();
return vector.iterator();
}
/**
* 修改新闻(ubb)
* @param newsId
*/
public Iterator editNews(int newsId){
Vector vector=new Vector();
if (sdbo==null)
sdbo = SQLDBOperator.getInstance("Connection");
String sql = "select * from news where newsId=?;";
try{
sdbo.prepareStatement(sql);
sdbo.setInt(1,newsId);
ResultSet rs = sdbo.executeQuery();
while(rs.next()){
NEWSTable tableNews=new NEWSTable();
tableNews.setClassId(rs.getInt("classId"));
tableNews.setKindId(rs.getInt("kindId"));
tableNews.setMyOther(rs.getInt("myOther"));
tableNews.setHeadTitle(CodeFilter.unHtml(rs.getString("headTitle")));
tableNews.setContent(CodeFilter.unHtml(rs.getString("content")));
tableNews.setConnect(CodeFilter.unHtml(rs.getString("connect")));
tableNews.setAuthor(rs.getString("author"));
tableNews.setEditor(rs.getString("editor"));
tableNews.setNewsFrom(rs.getString("newsFrom"));
tableNews.setTop(rs.getInt("top"));
vector.add(tableNews);
}
rs.close();
}
catch(Exception e){
System.out.print("News editNews() " + e.getMessage());
Debug.writeLog("News editNews(), Exception Occured ! Info :" + e.getLocalizedMessage());
}
finally{
sdbo.Close();
}
return vector.iterator();
}
/**
* 更新新闻
* @param newsId
*/
public void upNews(int classId,int kindId,int myOther,String headTitle,String content,String connect,String author,String editor,String newsFrom,int top,int newsId){
if (sdbo==null)
sdbo = SQLDBOperator.getInstance("Connection");
String sql = "update news set classId=?,kindId=?,myOther=?,headTitle=?,content=?,connect=?,author=?,editor=?,newsFrom=?,top=? where newsId=?;";
try{
sdbo.prepareStatement(sql);
sdbo.setInt(1, classId);
sdbo.setInt(2, kindId);
sdbo.setInt(3, myOther);
sdbo.setString(4, CodeFilter.toHtml(headTitle));
sdbo.setString(5, CodeFilter.toHtml(content));
sdbo.setString(6, CodeFilter.toHtml(connect));
sdbo.setString(7, CodeFilter.toHtml(author));
sdbo.setString(8, CodeFilter.toHtml(editor));
sdbo.setString(9, CodeFilter.toHtml(newsFrom));
sdbo.setInt(10, top);
sdbo.setInt(11, newsId);
sdbo.executeUpdate();
}
catch(Exception e){
System.out.print("News upNews() " +e.getMessage());
Debug.writeLog("News upNews(), Exception Occured ! Info :" + e.getLocalizedMessage());
}
finally{
sdbo.Close();
}
}
/**
* 更新新闻
* @param newsId
*/
public void upUbbNews(int classId,int kindId,int myOther,String headTitle,String content,String connect,String author,String editor,String newsFrom,int top,int newsId){
if (sdbo==null)
sdbo = SQLDBOperator.getInstance("Connection");
String sql = "update news set classId=?,kindId=?,myOther=?,headTitle=?,content=?,connect=?,author=?,editor=?,newsFrom=?,top=? where newsId=?;";
try{
sdbo.prepareStatement(sql);
sdbo.setInt(1, classId);
sdbo.setInt(2, kindId);
sdbo.setInt(3, myOther);
sdbo.setString(4, CodeFilter.toHtml(headTitle));
sdbo.setString(5, CodeFilter.toUbbHtml(content));
sdbo.setString(6, CodeFilter.toHtml(connect));
sdbo.setString(7, CodeFilter.toHtml(author));
sdbo.setString(8, CodeFilter.toHtml(editor));
sdbo.setString(9, CodeFilter.toHtml(newsFrom));
sdbo.setInt(10, top);
sdbo.setInt(11, newsId);
sdbo.executeUpdate();
}
catch(Exception e){
System.out.print("News upNews() " +e.getMessage());
Debug.writeLog("News upNews(), Exception Occured ! Info :" + e.getLocalizedMessage());
}
finally{
sdbo.Close();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -