jsp开发教程之 仿MOP论坛 三(帖子列表-上)
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
* @程序编写 阿汐
* @版本 1.0
* @说明 仿wc的jsp版本小论坛
* @本模块使用于数据库连接公用类
* @并且功能并不需要太多,因此本版本没有采用传统意义上的MVC开发模式,而是针对
* @vo,bo类进行了精简,用po类来共用vo类,用servlet类来共用bo类,很奇怪的开发模式
* @日期 2008.09.01
*
*/
public class DbUtil {
//数据库连接
public static Connection getConnection() {
try {
//数据库驱动驱动
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
//创建连接
String url = "jdbc:mysql://localhost/axbbs?user=root&password=root";
//设置连接
Connection con = DriverManager.getConnection(url);
return con;
} catch (Exception e) {
System.out.println("数据库连接失败!");
e.printStackTrace();
return null;
}
}
// 执行sql语句
public int execSQL(String sql) {
Connection con = getConnection();
Statement st = null;
int n = 0;
try {
st = con.createStatement();
} catch (SQLException e) {
System.out.println("error!");
e.printStackTrace();
}
try {
n = st.executeUpdate(sql);
} catch (SQLException e) {
System.out.println("error!");
e.printStackTrace();
} finally {
if (st != null)
try {
st.close();
} catch (SQLException e) {
System.out.println("error!");
e.printStackTrace();
}
if (con != null)
try {
con.close();
} catch (SQLException e) {
System.out.println("error!");
e.printStackTrace();
}
}
return n;
}
public ResultSet getResultSet(String sql) {
Connection con = getConnection();
Statement st = null;
ResultSet rs = null;
try {
st = con.createStatement();
} catch (SQLException e) {
System.out.println("数据库异常");
e.printStackTrace();
}
try {
rs = st.executeQuery(sql);
} catch (SQLException e) {
System.out.println("数据库异常");
e.printStackTrace();
}
return rs;
}
public void closeResultSet(ResultSet rs) {
try {
if (rs != null) {
Statement st = rs.getStatement();
Connection con = st.getConnection();
if (rs != null) {
rs.close();
}
if (st != null) {
st.close();
}
if (con != null) {
con.close();
}
}
} catch (Exception e) {
System.out.println("数据库连接失败");
e.printStackTrace();
}
}
}
package com.axbbs.Dao;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import com.axbbs.common.DbUtil;
import com.axbbs.po.PostPo;
/**
* @程序编写 阿汐
* @版本 1.0
* @说明 仿wc的jsp版本小论坛
* @本模块是用于获取帖子列表信息和帖子内容信息的DAO类
* @并且功能并不需要太多,因此本版本没有采用传统意义上的MVC开发模式,而是针对
* @vo,bo类进行了精简,用po类来共用vo类,用servlet类来共用bo类,很奇怪的开发模式
* @日期 2008.09.01
*
*/
public class GetPostListDAO {
/**
* @param args
*/
//创建数据工具包对象
private DbUtil dbUtil = new DbUtil();
//创建数据库连接
private Connection conn = dbUtil.getConnection();
public static void main(String[] args) {
//主方法测试方
//ArrayList l = new GetPostListDAO().getPost("1");
//System.out.print(((PostPo) l.get(0)).getPostUserName());
}
//帖子帖子列表信息
public ArrayList ViewList() {
ArrayList viewList = new ArrayList();
Statement stmt = null;
ResultSet rs = null;
String sql = "select * from MainPost";
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
PostPo pp = new PostPo();
pp.setPostId(rs.getInt("id"));
pp.setPostTitle(rs.getString("Post_Title"));
pp.setPostContent(rs.getString("Post_Content"));
pp.setPostUserName(rs.getString("Post_UserName"));
pp.setPosttime(rs.getString("Post_Time"));
pp.setPostReply(rs.getInt("Post_Reply"));
pp.setPostHits(rs.getInt("Post_Hits"));
viewList.add(pp);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return viewList;
}
//获得帖子信息
public ArrayList getPost(String id) {
ArrayList viewList = new ArrayList();
Statement stmt = null;
ResultSet rs = null;
String sql = "select * from MainPost where id='"+id+"'";
try {
stmt = conn.createStatement();
//执行查询获得主贴信息
rs = stmt.executeQuery(sql);
while (rs.next()) {
PostPo pp = new PostPo();
pp.setPostId(rs.getInt("id"));
pp.setPostTitle(rs.getString("Post_Title"));
pp.setPostContent(rs.getString("Post_Content"));
pp.setPostUserName(rs.getString("Post_UserName"));
pp.setPosttime(rs.getString("Post_Time"));
pp.setPostReply(rs.getInt("Post_Reply"));
pp.setPostHits(rs.getInt("Post_Hits"));
viewList.add(pp);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return viewList;
}
public void closeResultSet(ResultSet rs) {
try {
if (rs != null) {
Statement st = rs.getStatement();
Connection con = st.getConnection();
if (rs != null) {
rs.close();
}
if (st != null) {
st.close();
}
if (con != null) {
con.close();
}
}
} catch (Exception e) {
System.out.println("数据库连接关闭异常!");
e.printStackTrace();
}
}
}
/**
* @程序编写 阿汐
* @版本 1.0
* @说明 仿wc的jsp版本小论坛
* @本模块是帖子信息的PO类,帖子列表信息同样用此类,另外省去了VO类,为了精简
* @并且功能并不需要太多,因此本版本没有采用传统意义上的MVC开发模式,而是针对
* @vo,bo类进行了精简,用po类来共用vo类,用servlet类来共用bo类,很奇怪的开发模式
* @日期 2008.09.01
*
*/
public class PostPo {
//id
private int postId;
//帖子标题
private String postTitle;
//帖子内容
private String postContent;
//发帖人
private String postUserName;
//发帖时间
private String posttime;
//回复
private int postReply;
//点击
private int postHits;
/**
* @return postContent
*/
public String getPostContent() {
return postContent;
}
/**
* @param postContent 要设置的 postContent
*/
public void setPostContent(String postContent) {
this.postContent = postContent;
}
/**
* @return postHits
*/
public int getPostHits() {
return postHits;
}
/**
* @param postHits 要设置的 postHits
*/
public void setPostHits(int postHits) {
this.postHits = postHits;
}
/**
* @return postId
*/
public int getPostId() {
return postId;
}
/**
* @param postId 要设置的 postId
*/
public void setPostId(int postId) {
this.postId = postId;
}
/**
* @return postReply
*/
public int getPostReply() {
return postReply;
}
/**
* @param postReply 要设置的 postReply
*/
public void setPostReply(int postReply) {
this.postReply = postReply;
}
/**
* @return posttime
*/
public String getPosttime() {
return posttime;
}
/**
* @param posttime 要设置的 posttime
*/
public void setPosttime(String posttime) {
this.posttime = posttime;
}
/**
* @return postTitle
*/
public String getPostTitle() {
return postTitle;
}
/**
* @param postTitle 要设置的 postTitle
*/
public void setPostTitle(String postTitle) {
this.postTitle = postTitle;
}
/**
* @return postUserName
*/
public String getPostUserName() {
return postUserName;
}
/**
* @param postUserName 要设置的 postUserName
*/
public void setPostUserName(String postUserName) {
this.postUserName = postUserName;
}
}
转载于:https://blog.51cto.com/axiii/97506
jsp开发教程之 仿MOP论坛 三(帖子列表-上)相关推荐
- 【Cocos Creator游戏开发教程】仿微信趣味画赛车小游戏(三)代码实现
[Cocos Creator游戏开发教程]仿微信趣味画赛车小游戏(一)前言,界面UI [Cocos Creator游戏开发教程]仿微信趣味画赛车小游戏(二)物理刚体关节 项目地址已放到 github ...
- 【Cocos Creator游戏开发教程】仿微信趣味画赛车小游戏(二)物理刚体关节
[Cocos Creator游戏开发教程]仿微信趣味画赛车小游戏(一)前言,界面UI 项目地址已放到 github 上,需要的小伙伴可自行下载. 这节我们讲一下车子的物理刚体关节. 我在项目中添加了一 ...
- 【Cocos Creator游戏开发教程】仿微信趣味画赛车小游戏(一)前言,界面UI
前言 这个是我去年3月份在简书上发布的,不玩简书了,就迁到CSDN吧-- 最近遇到一款游戏,感觉玩起来还行,于是顺带就用来熟悉一下Cocos Creator(太久没用). 项目地址已放到 github ...
- 【Android 仿微信通讯录 导航分组列表-上】使用ItemDecoration为RecyclerView打造带悬停头部的分组列表
*本篇文章已授权微信公众号 guolin_blog (郭霖)独家发布 转载请标明出处: http://blog.csdn.net/zxt0601/article/details/52355199 本文 ...
- 动易网站首页调用动网论坛最新帖子列表的操作方法
动易网站首页调用动网论坛最新帖子列表的操作方法 以下采用的是:动易网站为swCMS6.5版 和 动网论坛为dvbbs 8.1.1 版 1. 确定动易swCMS6.5网站首页"论坛新帖& ...
- android studio游戏摇杆开发教程,仿王者荣耀摇杆
李子果 原创... 最近在做一个山寨版的王者荣耀,刚开始做的时候毫无头绪 摇杆的多点触控做的特别烂 经过几天的思考已完美解决所有问题,下面就和大家分享下这个摇杆的开发思路(此教程不包含游戏源码) 若有 ...
- 小程序开发教程,字节跳动Android三面凉凉,一篇文章帮你解答
开篇 说一下我大概的情况.渣本毕业,工作已经有快3年了,从高中就开始玩小破站.无论是学习还是日常放松都是在b站.大学主学的软件技术专业,所以,入职bilibili是我大学时期给自己定的小目标. 在学校 ...
- Kendo UI开发教程(25): 单页面应用(三) View
View为屏幕上某个可视部分,可以处理用户事件. View可以通过HTML创建或是通过script元素.缺省情况下View将其所包含的内容封装在一个Div元素中. Kendo创建View有两种方式: ...
- android 日历开发教程,android 开发教程之日历项目实践(三)
二.创建样式 日历显示的表格线,使用 Cell 填充图形的边框来实现,为了统一,我们先定义边框线的颜色及线条精细. 另外还要定义一系统填充样式等. 创建 color: color_calendar_b ...
最新文章
- 前端学习(540):node.js简介
- 会计行业被计算机取代马云,会计人:为什么我神烦“人工智能取代说”?
- 计算机实验报告14,计算机14实验报告模板.doc
- 出现梯度消失与梯度爆炸的原因以及解决方案
- 核心金融场景分布式事务
- Server.Variables属性大全(转载)
- 来自微信官方:微信支付跨平台软件架构首次曝光
- 堆排序Java代码实现
- 关于微信拼车小程序开发的需求分析(需求获取)
- 解决AxureRP经常性损坏问题
- 计算机保存到桌面显示不出来,excel表格在电脑桌面显示不出来是什么原因?
- One or more errors occurred 报错
- 深度|人脸图像的技术原理及在电商业务中的应用
- Latex 表格单元格内换行
- HackTheGame 攻略 - 第一关
- C++ - sstream标准库(串流控制)
- 数据分析——爬取股票数据
- AppServ 特来电共享充电桩PHPstudy系统开发
- 利用百度地图api抓取POI点(上海公交站)
- kibana去重统计和分组统计
热门文章
- python数据库操作sqlite_Python3操作SQLite数据库
- Mixed Finite Elements for Variational Surface Modeling
- change background color in chrome
- MATLAB关于Mesh的相关命令
- Deep Learning with PyTorch 必看教程集(4本)
- thttpd支持php吗,轻量型thttpd+php5
- python多重继承super父类参数_python – 多重继承如何与super()和不同的__init __()参数一起使用?...
- python 计时器_谁能取代Python?我使用Go来部署机器学习模型的原因
- js变量显示在html中_PythonDjango+JS+Ajax实现网页采集并动态显示PLC变量
- html5游戏开发-零基础开发《圣诞老人送礼物》小游戏