package dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import tip.Tip;
import user.User;
public class NewsDaoImp implements NewsDao {
String driver="org.hsqldb.jdbc.JDBCDriver";
String uri="jdbc:hsqldb:hsql://localhost:9001/";
String user="SA";
String pass="";
public List<String[]> getAllTips(String boardName) throws Exception {
String sql="select * from tip where boardName='"+boardName+"'";
List<String[]> tips=new ArrayList<>();
Class.forName(driver);
try(Connection con = DriverManager.getConnection(uri, user, pass);
PreparedStatement prstm = con.prepareStatement(sql);
ResultSet rs = prstm.executeQuery();){
while(rs.next()){
String[] r=new String[5];
r[0]=rs.getString("tipId");
r[1]=rs.getString("title");
r[2]=rs.getString("publishTime");
r[3]=rs.getString("userName");
r[4]=rs.getString("boardName");
tips.add(r);
}
}
return tips;
}
@Override
public ResultSet select(int id) {
String condition="SELECT * From board where boardId="+ id;
Statement st = null;
ResultSet rs = null;
try {
Class.forName(driver);
} catch (Exception e) {
e.printStackTrace();
}
try {
rs = st.executeQuery(condition);
} catch (SQLException e) {
e.printStackTrace();
}
return rs;
}
@Override
public boolean add(String title, String cont, String type) throws Exception {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
String date=df.format(new Date());
HttpServletRequest request=ServletActionContext.getRequest();
HttpSession session=request.getSession();
String userName=(String) session.getAttribute("name");
String condition ="INSERT INTO tip VALUES(?,?,?,?,?)";
int row=0;
Tip tip=null;
Class.forName(driver);
try (Connection con = DriverManager.getConnection(uri, user, pass);
PreparedStatement prstm = con.prepareStatement(condition);) {
tip=new Tip();
prstm.setString(1,title);
prstm.setString(2,cont);
prstm.setString(3,date);
prstm.setString(4,userName);
prstm.setString(5,type);
tip.setMessage("发布成功");
row=prstm.executeUpdate();
}catch(SQLException e){}
return row > 0 ? true : false;
}
@Override
public Tip show(int tipId) throws Exception {
String sql="select * from tip where tipId='"+tipId+"'";
Tip tips=null;
Class.forName(driver);
try (Connection con = DriverManager.getConnection(uri, user, pass);
PreparedStatement pstmt = con.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();) {
if(rs.next()){
tips=new Tip();
tips.setTipId(rs.getInt(1));
tips.setCont(rs.getString(3));
}
return tips;
}
}
@Override
public List<String[]> getTips(String key,int type) throws Exception {
HttpServletRequest request=ServletActionContext.getRequest();
HttpSession session=request.getSession();
String userName=(String) session.getAttribute("name");
List<String[]> tips=new ArrayList<>();
String condition=null;
if(type==1){
condition="select * from tip where title='"+key+"' and userName='"+userName+"'";
}
else if(type==2){
condition="select * from tip where userName='"+userName+"'";
}
Class.forName(driver);
try(Connection con = DriverManager.getConnection(uri, user, pass);
PreparedStatement prstm = con.prepareStatement(condition);
ResultSet rs = prstm.executeQuery();){
while(rs.next()){
String[] row=new String[5];
row[0]=rs.getString("tipId");
row[1]=rs.getString("title");
row[2]=rs.getString("publishTime");
row[3]=rs.getString("userName");
row[4]=rs.getString("boardName");
tips.add(row);
}
}
return tips;
}
@Override
public boolean update(Tip tip) throws Exception{
Class.forName(driver);
int id=tip.getTipId();
String condition="update tip set detail=? where tipId=?";
int row=0;
Tip tips=new Tip();
try (Connection con = DriverManager.getConnection(uri, user, pass);
PreparedStatement prstm= con.prepareStatement(condition);
) {
prstm.setString(1,tip.getCont());
prstm.setInt(2,id);
tip.setMessage("修改成功!");
row=prstm.executeUpdate();
return row > 0 ? true : false; }
}
@Override
public Tip query(int tipId) throws Exception {
Tip tip=null;
String condition="select * from tip where tipId='"+tipId+"'";
Class.forName(driver);
try(Connection con=DriverManager.getConnection(uri, user, pass);
Statement st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);){
ResultSet rs=st.executeQuery(condition);
if(rs.next()){
tip=new Tip();
tip.setTipId(tipId);
tip.setCont(rs.getString(3));
}
}
return tip;
}
@Override
public boolean delById(int tipId) throws Exception {
String sql = "delete from tip where tipId=?";
int row = 0;
Tip tip=new Tip();
Class.forName(driver);
try (Connection con = DriverManager.getConnection(uri, user, pass);
PreparedStatement pstmt = con.prepareStatement(sql);) {
pstmt.setInt(1,tipId);
row = pstmt.executeUpdate();
tip.setMessage("删除成功!");
}
return row > 0 ? true : false;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
1)用户注册、登录。登录后显示所有版块,单击版块,显示该板块下的所有帖子列表。单击帖子,显示内容和回帖。 2)管理员对版块管理,版块是动态,可增加、改名。 3)用户可以发新帖,能够回帖,不考虑回帖的回帖。用户可以浏览自己发的帖子,有自己所发帖子的列表。 4)单击帖子的作者,可以显示该作者的一些信息,可以在此给作者留言。 5)用户可以浏览发出、收到的留言。 6)留言中包含留言者昵称、标题、内容、时间等字段。
资源推荐
资源详情
资源评论
收起资源包目录
论坛管理系统(Struts2) (119个子文件)
NewsDaoImp.class 8KB
WordDaoImp.class 7KB
BoardIDaoImp.class 6KB
UserDaoImp.class 6KB
Tips.class 4KB
RegisterAction.class 4KB
ReplyDaoImp.class 4KB
Boards.class 3KB
Users.class 3KB
LoginAction.class 2KB
Board.class 2KB
Words.class 2KB
Tip.class 2KB
User.class 2KB
Replys.class 2KB
Word.class 2KB
Reply.class 1KB
LogOut.class 803B
NewsDao.class 694B
UserDao.class 491B
BoardDao.class 486B
WordDao.class 436B
ReplyDao.class 267B
.classpath 2KB
org.eclipse.wst.common.component 471B
org.eclipse.wst.jsdt.ui.superType.container 49B
freemarker-2.3.22.jar 1.24MB
struts2-core-2.3.24.jar 812KB
log4j-core-2.2.jar 807KB
xwork-core-2.3.24.jar 661KB
javassist-3.11.0.GA.jar 600KB
sqljdbc4.jar 571KB
commons-lang3-3.2.jar 376KB
ognl-3.0.6.jar 223KB
commons-io-2.2.jar 170KB
log4j-api-2.2.jar 130KB
commons-fileupload-1.3.1.jar 67KB
asm-3.3.jar 43KB
asm-commons-3.3.jar 37KB
asm-tree-3.3.jar 21KB
NewsDaoImp.java 6KB
WordDaoImp.java 5KB
BoardIDaoImp.java 5KB
UserDaoImp.java 4KB
Tips.java 3KB
RegisterAction.java 2KB
ReplyDaoImp.java 2KB
Boards.java 2KB
Users.java 2KB
Board.java 2KB
LoginAction.java 1KB
User.java 1KB
Words.java 1KB
Tip.java 1KB
Word.java 1007B
Replys.java 933B
Reply.java 789B
NewsDao.java 544B
LogOut.java 457B
UserDao.java 402B
BoardDao.java 383B
WordDao.java 356B
ReplyDao.java 233B
304477.jpg 460KB
304480.jpg 399KB
293075.jpg 323KB
304248.jpg 313KB
303487.jpg 312KB
304495.jpg 296KB
304286.jpg 279KB
303361.jpg 183KB
.jsdtscope 564B
adminshow.jsp 3KB
adminShowTip.jsp 3KB
delUser.jsp 3KB
userShowTip.jsp 3KB
board_list.jsp 3KB
adminQueryTip.jsp 3KB
adminPostTip.jsp 2KB
showUserIn.jsp 2KB
tipAdmin_list.jsp 2KB
userQueryTip.jsp 2KB
userPostTip.jsp 2KB
showUserIn1.jsp 2KB
userTip_list.jsp 2KB
admin.jsp 2KB
adminTip_list.jsp 2KB
adminShowBoard.jsp 2KB
board_update.jsp 2KB
tip_list.jsp 2KB
user.jsp 2KB
tipAdmin_update.jsp 2KB
admin_read.jsp 2KB
admin_unread.jsp 2KB
tip_update.jsp 2KB
addBoard.jsp 2KB
userShowBoard.jsp 2KB
user_read.jsp 2KB
user_unread.jsp 2KB
queryATip.jsp 2KB
共 119 条
- 1
- 2
资源评论
xili80
- 粉丝: 9
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功