package com.wxpn.tutorial.servlet;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import com.wxpn.tutorial.db.ConnectionPool;
import com.wxpn.tutorial.db.DB;
/**
* 描述: 描述留言信息管理类
*
* @Copyright (c) 2005-2008 Wang Xining
* @author 王夕宁
* @version 1.0
*/
public class BBSMsgMgr {
public int compose(BBSMsg msg) {
// 创建数据库连接对象:
ConnectionPool connPool = DB.getConnPool();
Connection conn = connPool.getConnection();
Statement stmt = null;
ResultSet rs = null;
try {
int maxid = 1;
String sql = "select max(item_id) as maxid from bbsitems";
// 创建数据记录集对象:
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
if (rs.next()) {
maxid = rs.getInt(1) + 1;
}
// sql语句:
sql = "insert into bbsitems(item_id,item_title,item_content,author,"
+ "compose_date,is_origional,fathers_id,replyed_times,browsed_times,"
+ "latest_replication_id,modify_date,face) values('"
+ maxid
+ "','"
+ msg.getItem_title()
+ "','"
+ msg.getItem_content()
+ "','"
+ msg.getAuthor()
+ "','"
+ msg.getStrCompose_date()
+ "','1','"
+ maxid
+ "','0','0','" + maxid + "','','" + msg.getFace() + "')";
// System.out.println(sql);
sql = new String(sql.getBytes("ISO8859-1"), "UTF-8");
// System.out.println(sql);
// 执行sql语句:
int i = stmt.executeUpdate(sql);
return i;
} catch (SQLException sqlExc) {
sqlExc.printStackTrace();
return -1;
} catch (Exception e) {
e.printStackTrace();
return -2;
} finally {
// 关闭连接,释放数据库资源:
try {
if (stmt != null) {
stmt.close();
}
connPool.freeConnection(conn);
} catch (SQLException sqlExc) {
sqlExc.printStackTrace();
}
}
}
public int modify(BBSMsg msg) {
// 创建数据库连接对象:
ConnectionPool connPool = DB.getConnPool();
Connection conn = connPool.getConnection();
Statement stmt = null;
try {
// 创建数据记录集对象:
stmt = conn.createStatement();
// sql语句:
String sql = "update bbsitems set item_title='"
+ msg.getItem_title() + "',item_content='"
+ msg.getItem_content() + "',modify_date='"
+ msg.getStrModify_date() + "',face='"+msg.getFace()+"' where item_id='"
+ msg.getItem_id() + "'";
// 执行sql语句:
System.out.println(sql);
sql = new String(sql.getBytes("ISO8859-1"), "UTF-8");
System.out.println(sql);
int i = stmt.executeUpdate(sql);
return i;
} catch (SQLException sqlExc) {
sqlExc.printStackTrace();
return -1;
} catch (Exception e) {
e.printStackTrace();
return -2;
} finally {
// 关闭连接,释放数据库资源:
try {
if (stmt != null) {
stmt.close();
}
connPool.freeConnection(conn);
} catch (SQLException sqlExc) {
sqlExc.printStackTrace();
}
}
}
public int read(int id) {
// 创建数据库连接对象:
ConnectionPool connPool = DB.getConnPool();
Connection conn = connPool.getConnection();
Statement stmt = null;
try {
// 创建数据记录集对象:
stmt = conn.createStatement();
// sql语句:
String sql = "update bbsitems set BROWSED_TIMES=BROWSED_TIMES+1 "
+ "where item_id='" + id + "'";
// System.out.println(sql);
// 执行sql语句:
int i = stmt.executeUpdate(sql);
return i;
} catch (SQLException sqlExc) {
sqlExc.printStackTrace();
return -1;
} catch (Exception e) {
e.printStackTrace();
return -2;
} finally {
// 关闭连接,释放数据库资源:
try {
if (stmt != null) {
stmt.close();
}
connPool.freeConnection(conn);
} catch (SQLException sqlExc) {
sqlExc.printStackTrace();
}
}
}
public int reply(BBSMsg msg, int fatherId) {
// 创建数据库连接对象:
ConnectionPool connPool = DB.getConnPool();
Connection conn = connPool.getConnection();
Statement stmt = null;
ResultSet rs = null;
try {
int maxid = 1;
String sql = "select max(item_id) as maxid from bbsitems";
// 创建数据记录集对象:
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
if (rs.next()) {
maxid = rs.getInt(1) + 1;
}
// sql语句:
sql = "insert into bbsitems(item_id,item_title,item_content,author,"
+ "compose_date,is_origional,fathers_id,replyed_times,browsed_times,"
+ "latest_replication_id,face) values('"
+ maxid
+ "','"
+ msg.getItem_title()
+ "','"
+ msg.getItem_content()
+ "','"
+ msg.getAuthor()
+ "','"
+ msg.getStrCompose_date()
+ "','0','"
+ fatherId
+ "','0','0','" + maxid + "','" + msg.getFace() + "')";
sql = new String(sql.getBytes("ISO8859-1"), "UTF-8");
stmt.addBatch(sql);
sql = "update bbsitems set replyed_times=replyed_times+1,latest_replication_id='"
+ maxid + "' where item_id='" + fatherId + "'";
stmt.addBatch(sql);
// 执行sql语句:
stmt.executeBatch();
return 1;
} catch (SQLException sqlExc) {
sqlExc.printStackTrace();
return -1;
} catch (Exception e) {
e.printStackTrace();
return -2;
} finally {
// 关闭连接,释放数据库资源:
try {
if (stmt != null) {
stmt.close();
}
connPool.freeConnection(conn);
} catch (SQLException sqlExc) {
sqlExc.printStackTrace();
}
}
}
public int delete(int id) {
// 创建数据库连接对象:
ConnectionPool connPool = DB.getConnPool();
Connection conn = connPool.getConnection();
Statement stmt = null;
try {
// 创建数据记录集对象:
stmt = conn.createStatement();
// sql语句:
String sql = "delete from bbsitems where item_id = '" + id + "'";
stmt.addBatch(sql);
Collection c = getFamily(id);
if (c != null) {
Iterator iterator = c.iterator();
while (iterator.hasNext()) {
sql = "delete from bbsitems where item_id = '"
+ ((Integer) iterator.next()).intValue() + "'";
// System.out.println("sql:" + sql);
stmt.addBatch(sql);
}
}
// 执行sql语句:
stmt.executeBatch();
return 1;
} catch (SQLException sqlExc) {
sqlExc.printStackTrace();
return -1;
} catch (Exception e) {
e.printStackTrace();
return -2;
} finally {
// 关闭连接,释放数据库资源:
try {
if (stmt != null) {
stmt.close();
}
connPool.freeConnection(conn);
} catch (SQLException sqlExc) {
sqlExc.printStackTrace();
}
}
}
public Collection getFamily(int id) {
// 创建数据库连接对象:
ConnectionPool connPool = DB.getConnPool();
Connection conn = connPool.getConnection();
Statement stmt = null;
ResultSet rs = null;
try {
// 创建数据记录集对象:
stmt = conn.createStatement();
// sql语句:
String sql = "select item_id from bbsitems where fathers_id='" + id
+ "' and item_id!='" + id + "'";
// System.out.println(sql);
// 执行sql语句,返回一个记录集到rs:
rs = stmt.executeQuery(sql);
Collection c = new ArrayList();
while (rs.next()) {
if (c == null) {
c = new ArrayList();
}
int item_id = rs.getInt("item_id");
c.add(new Integer(item_id));
c.addAll(getFamily(item_id));
}
return c;
} catch (SQLException sqlExc) {
sqlExc.printStackTrace();
return null;
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
// 关闭连接,释放数据库资源:
try {
if (rs != null) {
rs.close();
}
if (stmt != null) {
stmt.close();
}
connPool.freeConnection(conn);
} catch (SQLException sqlExc) {
sqlExc.printStackTrace();
}
}
}
public Collection getFamilyLevel(int id, int level) {
// 创建数据库连接对象:
没有合适的资源?快使用搜索试试~ 我知道了~
BBS.zip_MyEclipse BBS_myeclipse_mysql实现讨论_讨论区系统
共136个文件
gif:80个
jsp:16个
java:12个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 78 浏览量
2022-09-19
20:31:28
上传
评论
收藏 749KB ZIP 举报
温馨提示
一个在mysql+myeclipse+tomcat的BBS讨论区的设计源代码,它给出了一个完整的BBS系统,实现了BBS要求的基本功能。
资源推荐
资源详情
资源评论
收起资源包目录
BBS.zip_MyEclipse BBS_myeclipse_mysql实现讨论_讨论区系统 (136个子文件)
BBSMsgMgr.class 19KB
ConnectionPool.class 9KB
BBSMsg.class 4KB
DB.class 3KB
ModifyServlet.class 2KB
LoginServlet.class 2KB
Encoder.class 2KB
ReadServlet.class 2KB
DeleteServlet.class 2KB
ComposeServlet.class 1KB
BrowseServlet.class 1KB
ReplyServlet.class 1KB
.classpath 744B
org.eclipse.wst.jsdt.ui.superType.container 49B
38.gif 1KB
38.gif 1KB
11.gif 1KB
11.gif 1KB
29.gif 902B
29.gif 902B
33.gif 895B
33.gif 895B
30.gif 894B
30.gif 894B
31.gif 891B
31.gif 891B
32.gif 880B
32.gif 880B
39.gif 878B
39.gif 878B
8.gif 798B
8.gif 798B
35.gif 780B
35.gif 780B
23.gif 702B
23.gif 702B
21.gif 563B
21.gif 563B
24.gif 538B
24.gif 538B
40.gif 439B
40.gif 439B
17.gif 431B
17.gif 431B
3.gif 359B
4.gif 359B
3.gif 359B
4.gif 359B
13.gif 341B
13.gif 341B
2.gif 332B
2.gif 332B
1.gif 324B
1.gif 324B
5.gif 322B
5.gif 322B
34.gif 249B
34.gif 249B
14.gif 227B
14.gif 227B
12.gif 226B
12.gif 226B
27.gif 182B
27.gif 182B
16.gif 162B
16.gif 162B
7.gif 152B
7.gif 152B
6.gif 143B
6.gif 143B
19.gif 140B
19.gif 140B
9.gif 138B
10.gif 138B
9.gif 138B
10.gif 138B
26.gif 136B
15.gif 136B
26.gif 136B
15.gif 136B
22.gif 135B
22.gif 135B
37.gif 131B
37.gif 131B
36.gif 129B
36.gif 129B
20.gif 108B
20.gif 108B
28.gif 100B
28.gif 100B
18.gif 97B
18.gif 97B
25.gif 94B
25.gif 94B
mysql-connector-java-3.1.10-bin.jar 409KB
mm.mysql-2.0.14.jar 123KB
mm.mysql-2.0.14.jar 123KB
BBSMsgMgr.java 19KB
ConnectionPool.java 16KB
BBSMsg.java 4KB
共 136 条
- 1
- 2
资源评论
林当时
- 粉丝: 98
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功