- package StudyBbs;
- import java.util.*;
- import java.sql.Connection;
- import java.sql.ResultSet;
- public class Respond{
- private int id;
- private String title;
- private String content;
- private String owner;
- private String time;
- private int topicid ;
- private String grade;
- private String nickname;
- private String memo;
- public Respond(){}
- public void setId(int id) {
- this.id = id;
- }
- public void setTitle(String title) {
- this.title = title;
- }
- public void setContent(String content) {
- this.content = content;
- }
- public void setOwner(String owner) {
- this.owner = owner;
- }
- public void setTime(String time) {
- this.time = time;
- }
- public void setTopicid(int topicid) {
- this.topicid = topicid;
- }
- public void setGrade(String grade) {
- this.grade = grade;
- }
- public void setNickname(String nickname) {
- this.nickname = nickname;
- }
- public void setMemo(String memo) {
- this.memo = memo;
- }
- public int getId(){
- return id;
- }
- public String getTitle(){
- return title;
- }
- public String getContent(){
- return content;
- }
- public String getOwner(){
- return owner;
- }
- public String getTime(){
- return time;
- }
- public int getTopictid(){
- return topicid;
- }
- public String getGrade(){
- return grade;
- }
- public String getNickname(){
- return nickname;
- }
- public String getMemo(){
- return memo;
- }
- public boolean Insert(DB db) throws Exception{
- String strSql;
- ResultSet rs;
- int iMaxId;
- strSql = "Select max(id) From responses";
- rs = db.OpenSql(strSql);
- if ( rs.next()) {
- iMaxId=rs.getInt(1)+1;
- }
- else{
- iMaxId=1;
- }
- strSql = "insert into responses values("
- + iMaxId +",'"
- + title +"','"
- + content +"','"
- + owner +"',sysdate,"
- + topicid +")";
- if ( db.ExecSql(strSql)==0) {
- return false;
- }
- else{
- return true;
- }
- }
- public static Vector search(DB db ,int topicid) throws Exception{
- Vector Contents = new Vector();
- ResultSet rs,rsNest;
- String strSql=null;
- strSql = "select * from topic where id=" + topicid;
- rs = db.OpenSql(strSql);
- if (rs.next()){
- Respond resp = new Respond();
- resp.setId(rs.getInt("id"));
- resp.setTitle ( rs.getString("topicname"));
- resp.setContent ( rs.getString("topiccontent"));
- resp.setOwner ( rs.getString("owner"));
- resp.setTime ( rs.getString("time"));
- resp.setTopicid ( topicid);
- strSql = "select * from bbsuser where username='" + resp.getOwner() + "'";
- rsNest = db.OpenSql(strSql);
- if (rsNest.next()){
- resp.setGrade(rsNest.getString("usergrade"));
- resp.setNickname(rsNest.getString("nickname"));
- resp.setMemo(rsNest.getString("signature"));
- }
- Contents.add(resp);
- }
- strSql = "select * from responses where topicid=" + topicid + " order by time desc";
- rs = db.OpenSql(strSql);
- int iCount=0;
- while(rs.next()){
- Respond resp = new Respond();
- resp.setId(rs.getInt("id"));
- resp.setTitle ( rs.getString("title"));
- resp.setContent ( rs.getString("content"));
- resp.setOwner ( rs.getString("owner"));
- resp.setTime ( rs.getString("time"));
- resp.setTopicid ( topicid);
- strSql = "select * from bbsuser where username='" + resp.getOwner() + "'";
- rsNest = db.OpenSql(strSql);
- if (rsNest.next()){
- resp.setGrade(rsNest.getString("usergrade"));
- resp.setNickname(rsNest.getString("nickname"));
- resp.setMemo(rsNest.getString("signature"));
- }
- Contents.add(resp);
- }
- return Contents;
- }
- }