?? newsshow.java
字號:
package com.ntsky.news;
/**
* <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.sql.*;
import java.util.*;
import com.ntsky.common.*;
import com.ntsky.database.*;
import com.ntsky.persistence.*;
public class NewsShow {
private SQLDBOperator sdbo=null;
/**
* 本站發表的文章總數
*/
public int sumNews(){
int sum=0;
if (sdbo==null)
sdbo = SQLDBOperator.getInstance("Connection");
ResultSet rs=null;
String strSql = "select count(newsId) as total from news where state=1;";
try{
rs = sdbo.executeQuery(strSql);
try{
rs.next();
sum=rs.getInt("total");
rs.close();
}
catch(NullPointerException nullE){
System.out.print("NewsShow sumNews() " +nullE.getMessage());
Debug.writeLog("NewsShow sumNews(), Exception Occured ! Info :" + nullE.getLocalizedMessage());
}
}
catch(SQLException sqlE){
System.out.print("NewsShow sumNews() " +sqlE.getMessage());
Debug.writeLog("NewsShow sumNews(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
}
finally{
sdbo.Close();
}
return sum;
}
/**
* 本站注冊的用戶總數
*/
public int sumUser(){
int sum=0;
if (sdbo==null)
sdbo = SQLDBOperator.getInstance("Connection");
ResultSet rs=null;
String strSql = "select count(userName) as total from newsusr;";
try{
rs = sdbo.executeQuery(strSql);
try{
rs.next();
sum = rs.getInt("total");
rs.close();
}
catch(NullPointerException nullE){
System.out.print("NewsShow sumUser() " +nullE.getMessage());
Debug.writeLog("NewsShow sumUser(), Exception Occured ! Info :" + nullE.getLocalizedMessage());
}
}
catch(SQLException sqlE){
System.out.print("NewsShow sumUser() " +sqlE.getMessage());
Debug.writeLog("NewsShow sumUser(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
}
finally{
sdbo.Close();
}
return sum;
}
/**
* 網站最近更新的時間
*/
//判斷初始有無值
public boolean isTime(){
ResultSet rs=null;
if (sdbo==null)
sdbo = SQLDBOperator.getInstance("Connection");
boolean isTime=false;
String strSql = "select newsId from news where state=1;";
try{
rs = sdbo.executeQuery(strSql);
try{
rs.last();
if(rs.getRow()>0){
isTime=true;
}
rs.close();
}
catch(NullPointerException nullE){
System.out.print("NewsShow isTime() " +nullE.getMessage());
Debug.writeLog("NewsShow isTime(), Exception Occured ! Info :" + nullE.getLocalizedMessage());
}
}
catch(SQLException sqlE){
System.out.print("NewsShow isTime() " +sqlE.getMessage());
Debug.writeLog("NewsShow isTime(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
}
finally{
sdbo.Close();
}
return isTime;
}
//取得具體的時間
public String lastTime(){
if (sdbo==null)
sdbo = SQLDBOperator.getInstance("Connection");
ResultSet rs=null;
String newsTime = null;
String strSql = "select newsTime from news where state=1 order by newsTime desc;";
try{
rs = sdbo.executeQuery(strSql);
try{
rs.next();
newsTime=rs.getString("newsTime");
}
catch(NullPointerException nullE){
System.out.print("NewsShow lastTime() " +nullE.getMessage());
Debug.writeLog("NewsShow lastTime(), Exception Occured ! Info :" + nullE.getLocalizedMessage());
}
}
catch(SQLException sqlE){
System.out.print("NewsShow lastTime() " +sqlE.getMessage());
Debug.writeLog("NewsShow lastTime(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
}
finally{
sdbo.Close();
}
return newsTime;
}
/**
* 判斷有無的文章
*/
public boolean isNews(){
boolean isNews=false;
if (sdbo==null)
sdbo = SQLDBOperator.getInstance("Connection");
ResultSet rs=null;
String strSql = "select newsId from news where state=1;";
try{
rs = sdbo.executeQuery(strSql);
try{
rs.last();
if(rs.getRow()>0){
isNews=true;
}
rs.close();
}
catch(NullPointerException nullE){
System.out.print("NewsShow isTopNews() " +nullE.getMessage());
Debug.writeLog("NewsShow isTopNews(), Exception Occured ! Info :" + nullE.getLocalizedMessage());
}
}
catch(SQLException sqlE){
System.out.print("NewsShow isTopNews() " +sqlE.getMessage());
Debug.writeLog("NewsShow isTopNews(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
}
finally{
sdbo.Close();
}
return isNews;
}
/**
* 判斷有無前綴的文章
* @return
*/
public boolean isTopNews(){
if (sdbo==null)
sdbo = SQLDBOperator.getInstance("Connection");
boolean isTopNews=false;
ResultSet rs=null;
String strSql = "select newsId from news where state=1 and top=1;";
try{
rs = sdbo.executeQuery(strSql);
try{
rs.last();
if(rs.getRow()>0){
isTopNews=true;
}
rs.close();
}
catch(NullPointerException nullE){
System.out.print("NewsShow isTopNews() " +nullE.getMessage());
Debug.writeLog("NewsShow isTopNews(), Exception Occured ! Info :" + nullE.getLocalizedMessage());
}
}
catch(SQLException sqlE){
System.out.print("NewsShow isTopNews() " +sqlE.getMessage());
Debug.writeLog("NewsShow isTopNews(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
}
finally{
sdbo.Close();
}
return isTopNews;
}
/**
* 最新的記錄(前綴)
*/
public Iterator topNews(){
ResultSet rs=null;
if (sdbo==null)
sdbo = SQLDBOperator.getInstance("Connection");
Vector vector=new Vector();
String strSql = "select newsId,classId,headTitle from news where state=1 and top=1 order by newsTime desc limit 0,1;";
try{
rs = sdbo.executeQuery(strSql);
try{
while(rs.next()){
NEWSTable tableNews = new NEWSTable();
tableNews.setNewsId(rs.getInt("newsId"));
tableNews.setClassId(rs.getInt("classId"));
tableNews.setHeadTitle(rs.getString("headTitle"));
vector.add(tableNews);
}
rs.close();
}
catch(NullPointerException nullE){
System.out.print("NewsShow topNews() " +nullE.getMessage());
Debug.writeLog("NewsShow topNews(), Exception Occured ! Info :" + nullE.getLocalizedMessage());
}
}
catch(SQLException sqlE){
System.out.print("NewsShow topNews() " +sqlE.getMessage());
Debug.writeLog("NewsShow topNews(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
}
finally{
sdbo.Close();
}
return vector.iterator();
}
/**
* 判斷最新的文章(不用前綴)
*/
public boolean isNewNews(){
ResultSet rs=null;
if (sdbo==null)
sdbo = SQLDBOperator.getInstance("Connection");
boolean isNewNews=false;
Vector vector=new Vector();
String strSql = "select newsId from news where state=1 and top=0;";
try{
rs = sdbo.executeQuery(strSql);
try{
rs.last();
if(rs.getRow()>0){
isNewNews=true;
}
rs.close();
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -