?? listinfo.java
字號:
package com.ntsky.note;
/**
* <p>Title: NtSky留言本v1.2 servelet版</p>
* <p>Description: 列出留言信息</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: NTsky</p>
* @author 姚君林
* @version 1.0
*/
import java.io.*;
import java.sql.*;
import java.util.*;
import com.ntsky.note.Debug;
import com.ntsky.note.GuestTable;
import com.ntsky.note.ReplyTable;
import com.ntsky.note.URLServlet;
import com.ntsky.note.SQLDBOperator;
public class ListInfo {
private SQLDBOperator sdbo = null;
/**
* 總和
* @return sum
*/
public int sumNote(){
int sum=0;
ResultSet rs = null;
if(sdbo == null)
sdbo = SQLDBOperator.getInstance("Connection");
String strSql = "select count(*) as total from guest;";
try{
rs = sdbo.executeQuery(strSql);
rs.next();
sum = rs.getInt("total");
}
catch(Exception e){
System.out.print(e.getLocalizedMessage());
}
finally{
sdbo.Close();
}
return sum;
}
/**
* 取得信息
* @return
*/
public Enumeration listInfo(){
if(sdbo == null)
sdbo = SQLDBOperator.getInstance("Connection");
Vector v = new Vector();
try{
String strSql = "select * from guest order by noteTime desc;";
ResultSet rs = sdbo.executeQuery(strSql);
while(rs.next()){
GuestTable tableGuest = new GuestTable();
tableGuest.setNoteId(rs.getInt("noteId"));
tableGuest.setUserName(rs.getString("userName"));
tableGuest.setSex(rs.getInt("sex"));
tableGuest.setEmail(rs.getString("email"));
tableGuest.setQq(rs.getString("qq"));
tableGuest.setUrl(rs.getString("url"));
tableGuest.setHeadTitle(rs.getString("headTitle"));
tableGuest.setContent(rs.getString("content"));
tableGuest.setImage(rs.getString("image"));
tableGuest.setNoteTime(rs.getString("noteTime"));
v.add(tableGuest);
}
rs.close();
}
catch(Exception e){
System.out.print(e.getMessage());
}
finally{
sdbo.Close();
}
return v.elements();
}
/**
* 性別
*/
public String getSex(int sex){
String strSex = "男";
if(sex==0)
return strSex;
else
return strSex="女";
}
//判斷有無回復(fù)
public boolean isReply(int noteId){
if (sdbo==null)
sdbo = SQLDBOperator.getInstance("Connection");
boolean isReply=false;
String sql = "select count(replyId) from reply where noteId=?;";
try{
sdbo.prepareStatement(sql);
sdbo.setInt(1, noteId);
ResultSet rs = sdbo.executeQuery();
rs.next();
int sum = rs.getInt(1);
if(sum>0){
isReply=true;
}
rs.close();
}
catch(Exception e){
System.out.print("ListInfo isReply() " + e.getMessage());
Debug.writeLog("ListInfo isReply(), Exception Occured ! Info :" + e.getLocalizedMessage());
}
finally{
sdbo.Close();
}
return isReply;
}
//列出回復(fù)的內(nèi)容
public Iterator listReply(int noteId){
if (sdbo==null)
sdbo = SQLDBOperator.getInstance("Connection");
String sql = "select replyTime,content from reply where noteId=?;";
Vector vector = new Vector();
try{
sdbo.prepareStatement(sql);
sdbo.setInt(1,noteId);
ResultSet rs = sdbo.executeQuery();
while(rs.next()){
ReplyTable replyTable = new ReplyTable();
replyTable.setReplyTime(rs.getString("replyTime"));
replyTable.setContent(rs.getString("content"));
vector.add(replyTable);
}
rs.close();
}
catch(Exception e){
System.out.print("Guest listreply() " + e.getMessage());
Debug.writeLog("Guest listreply(), Exception Occured ! Info :" + e.getLocalizedMessage());
}
finally{
sdbo.Close();
}
return vector.iterator();
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -