?? topnews.java
字號:
package popten.web;
/****************************************
* news_title POPTEN *
* @author: 邊緣孤客 *
* Company: http://www.popten.com *
* Copyright: Copyright (c) 2002-10-1 *
* @version 1.0 beta *
****************************************/
import popten.db.DBConnect;
import popten.util.*;
import java.io.*;
import java.sql.*;
import java.util.*;
public class TopNews{
private String news_id,news_title;
public String getnews_id() { return news_id;}
public String getnews_title() { return news_title;}
public void setnews_id(String news_id) { this.news_id = news_id; }
public void setnews_title(String news_title) { this.news_title = news_title; }
public TopNews(){}
/**********************
* 添加新資料 *
**********************/
public static void addNews(String news_id,String news_title) throws Exception {
boolean foundErr = false;
String errMsg="";
DBConnect dbc = new DBConnect();
String today=GetDate.getStringDateShort();
ResultSet rs;
if(news_title.equals("") || news_title==null){
errMsg = errMsg + "□ 您沒有輸入標(biāo)題!<br>□ 五秒鐘后會自動返回上一頁。<br><meta HTTP-EQUIV=REFRESH CONTENT='5; URL=javascript:history.go(-1)'>";
foundErr = true;
}
if(news_id.equals("") || news_id==null){
errMsg = errMsg + "□ 您沒有輸入序號!<br>□ 五秒鐘后會自動返回上一頁。<br><meta HTTP-EQUIV=REFRESH CONTENT='5; URL=javascript:history.go(-1)'>";
foundErr = true;
}
try{
if(!foundErr){
dbc.prepareStatement("Select * from daytop where WEEK(dat)=(WEEK(NOW())-1)");
rs=dbc.executeQuery();
if(!rs.next()){
dbc.prepareStatement("Select * from daytop where news_id=?");
dbc.setBytes(1,news_id.getBytes("GBK"));
rs=dbc.executeQuery();
if(rs.next()){
if(today.equals(rs.getString("dat"))){
dbc.prepareStatement("update daytop set coun_day=coun_day+1,coun_week=coun_week+1 where news_id=?");
dbc.setBytes(1,news_id.getBytes("GBK"));
dbc.executeUpdate();
}
else{
dbc.prepareStatement("update daytop set dat=Now(),coun_day='1',coun_week=coun_week+1 where news_id=?");
dbc.setBytes(1,news_id.getBytes("GBK"));
dbc.executeUpdate();
}
}
else{
dbc.prepareStatement("insert into daytop set news_id=?,news_title=?,dat=Now(),coun_day='1',coun_week='1'");
dbc.setBytes(1,news_id.getBytes("GBK"));
dbc.setBytes(2,news_title.getBytes("GBK"));
dbc.executeUpdate();
}
}
else{
dbc.prepareStatement("delete from daytop WHERE WEEK(dat)=(WEEK(NOW())-1)");
dbc.executeUpdate();
dbc.prepareStatement("alter table daytop drop day_id");
dbc.executeUpdate();
dbc.prepareStatement("alter table daytop add day_id TINYINT unsigned auto_increment primary key");
dbc.executeUpdate();
dbc.prepareStatement("insert into daytop set news_id=?,news_title=?,dat=Now(),coun_day='1',coun_week='1'");
dbc.setBytes(1,news_id.getBytes("GBK"));
dbc.setBytes(2,news_title.getBytes("GBK"));
dbc.executeUpdate();
}
}
}
catch(Exception e){
System.err.println(e);
}
finally{
try{
dbc.close();
}
catch(Exception e){
e.printStackTrace();
}
}
}
/************************
* 讀出本周TOP10資料 *
************************/
public Vector WeekTop10(){
DBConnect dbc = null;
ResultSet rs;
Vector newsVector = new Vector();
try{
dbc = new DBConnect();
dbc.prepareStatement("select * from daytop order by coun_week desc limit 10");
rs = dbc.executeQuery();
while(rs.next()){
TopNews news = new TopNews();
news.setnews_id(rs.getString("news_id"));
news.setnews_title(rs.getString("news_title"));
newsVector.add(news);
}
}
catch(Exception e){
System.err.println(e);
}
finally{
try{
dbc.close();
}
catch(Exception e){
e.printStackTrace();
}
}
return newsVector;
}
/************************
* 讀出今天TOP10資料 *
************************/
public Vector DayTop10(){
DBConnect dbc = null;
ResultSet rs;
Vector newsVector = new Vector();
try{
dbc = new DBConnect();
dbc.prepareStatement("select * from daytop where TO_DAYS(dat)=TO_DAYS(NOW()) order by coun_day desc limit 10");
rs = dbc.executeQuery();
while(rs.next()){
TopNews news = new TopNews();
news.setnews_id(rs.getString("news_id"));
news.setnews_title(rs.getString("news_title"));
newsVector.add(news);
}
}
catch(Exception e){
System.err.println(e);
}
finally{
try{
dbc.close();
}
catch(Exception e){
e.printStackTrace();
}
}
return newsVector;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -