⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 listinfo.java

📁 一个基于java的记事本
💻 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="女";
    }
    //判断有无回复
    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;
    }
    //列出回复的内容
    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();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -