package com.sanqing.daoImpl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.sanqing.bean.Vote;
import com.sanqing.dao.VoteDAO;
import com.sanqing.util.DBConnection;
import com.sanqing.util.Page;
public class VoteDAOImpl implements VoteDAO{
public void addVote(Vote vote) {
Connection conn = DBConnection.getConnection(); //获得连接对象
String addSQL = "insert into " +
"tb_vote(voteName,channelID) values(?,?)";
PreparedStatement pstmt = null; //声明预处理对象
try {
pstmt = conn.prepareStatement(addSQL); //获得预处理对象并赋值
pstmt.setString(1, vote.getVoteName()); //设置投票名称
pstmt.setInt(2, vote.getChannelID()); //设置频道ID
pstmt.executeUpdate(); //执行添加
} catch (SQLException e) {
e.printStackTrace();
} finally{
DBConnection.close(pstmt); //关闭预处理对象
DBConnection.close(conn); //关闭连接对象
}
}
public void deleteVote(int voteID) {
Connection conn = DBConnection.getConnection(); //获得连接对象
String deleteSQL = "delete from tb_vote where voteID=?";
PreparedStatement pstmt = null; //声明预处理对象
try {
pstmt = conn.prepareStatement(deleteSQL); //获得预处理对象并赋值
pstmt.setInt(1, voteID); //设置投票编号
pstmt.executeUpdate(); //执行删除
} catch (SQLException e) {
e.printStackTrace();
} finally{
DBConnection.close(pstmt); //关闭预处理对象
DBConnection.close(conn); //关闭连接对象
}
}
public List<Vote> findAllVote(Page page) {
Connection conn = DBConnection.getConnection(); //获得连接对象
String findByIDSQL = "select * from tb_vote limit ?,?"; //查询SQL语句
PreparedStatement pstmt = null; //声明预处理对象
ResultSet rs = null;
List<Vote> votes = new ArrayList<Vote>();
try {
pstmt = conn.prepareStatement(findByIDSQL); //获得预处理对象并赋值
pstmt.setInt(1, page.getBeginIndex());
pstmt.setInt(2, page.getEveryPage());
rs = pstmt.executeQuery(); //执行查询
while(rs.next()) {
Vote vote = new Vote();
vote.setVoteID(rs.getInt(1));
vote.setVoteName(rs.getString(2));
vote.setChannelID(rs.getInt(3));
votes.add(vote);
}
} catch (SQLException e) {
e.printStackTrace();
} finally{
DBConnection.close(rs); //关闭结果集对象
DBConnection.close(pstmt); //关闭预处理对象
DBConnection.close(conn); //关闭连接对象
}
return votes;
}
public Vote findVoteById(int voteID) {
Connection conn = DBConnection.getConnection(); //获得连接对象
String querySQL = "select * from tb_vote where voteID = ?";
PreparedStatement pstmt = null; //声明预处理对象
ResultSet rs = null;
Vote vote = null;
try {
pstmt = conn.prepareStatement(querySQL); //获得预处理对象并赋值
pstmt.setInt(1, voteID);
rs = pstmt.executeQuery(); //执行查询
if(rs.next()) {
vote = new Vote();
vote.setVoteID(rs.getInt(1));
vote.setVoteName(rs.getString(2));
vote.setChannelID(rs.getInt(3));
}
} catch (SQLException e) {
e.printStackTrace();
} finally{
DBConnection.close(rs); //关闭结果集对象
DBConnection.close(pstmt); //关闭预处理对象
DBConnection.close(conn); //关闭连接对象
}
return vote;
}
public void updateVote(Vote vote) {
}
public Vote findVoteByName(String voteName) {
Connection conn = DBConnection.getConnection(); //获得连接对象
String querySQL = "select * from tb_vote where voteName = ?";
PreparedStatement pstmt = null; //声明预处理对象
ResultSet rs = null;
Vote vote = null;
try {
pstmt = conn.prepareStatement(querySQL); //获得预处理对象并赋值
pstmt.setString(1, voteName);
rs = pstmt.executeQuery(); //执行查询
if(rs.next()) {
vote = new Vote();
vote.setVoteID(rs.getInt(1));
vote.setVoteName(rs.getString(2));
vote.setChannelID(rs.getInt(3));
}
} catch (SQLException e) {
e.printStackTrace();
} finally{
DBConnection.close(rs); //关闭结果集对象
DBConnection.close(pstmt); //关闭预处理对象
DBConnection.close(conn); //关闭连接对象
}
return vote;
}
public int findAllCount() {
Connection conn = DBConnection.getConnection(); //获得连接对象
String findSQL = "select count(*) from tb_vote";
PreparedStatement pstmt = null; //声明预处理对象
ResultSet rs = null;
int count = 0;
try {
pstmt = conn.prepareStatement(findSQL); //获得预处理对象并赋值
rs = pstmt.executeQuery(); //执行查询
if(rs.next()) {
count = rs.getInt(1);
}
} catch (SQLException e) {
e.printStackTrace();
} finally{
DBConnection.close(rs); //关闭结果集对象
DBConnection.close(pstmt); //关闭预处理对象
DBConnection.close(conn); //关闭连接对象
}
return count;
}
public List<Vote> findVoteByChannel(Page page, int channelID) {
Connection conn = DBConnection.getConnection(); //获得连接对象
String findByIDSQL = "select * from tb_vote where channelID=? limit ?,?"; //查询SQL语句
PreparedStatement pstmt = null; //声明预处理对象
ResultSet rs = null;
List<Vote> votes = new ArrayList<Vote>();
try {
pstmt = conn.prepareStatement(findByIDSQL); //获得预处理对象并赋值
pstmt.setInt(1, channelID);
pstmt.setInt(2, page.getBeginIndex());
pstmt.setInt(3, page.getEveryPage());
rs = pstmt.executeQuery(); //执行查询
while(rs.next()) {
Vote vote = new Vote();
vote.setVoteID(rs.getInt(1));
vote.setVoteName(rs.getString(2));
vote.setChannelID(rs.getInt(3));
votes.add(vote);
}
} catch (SQLException e) {
e.printStackTrace();
} finally{
DBConnection.close(rs); //关闭结果集对象
DBConnection.close(pstmt); //关闭预处理对象
DBConnection.close(conn); //关闭连接对象
}
return votes;
}
public int fintCountByChannel(int channelID) {
Connection conn = DBConnection.getConnection(); //获得连接对象
String findSQL = "select count(*) from tb_vote where channelID=?";
PreparedStatement pstmt = null; //声明预处理对象
ResultSet rs = null;
int count = 0;
try {
pstmt = conn.prepareStatement(findSQL); //获得预处理对象并赋值
pstmt.setInt(1, channelID);
rs = pstmt.executeQuery(); //执行查询
if(rs.next()) {
count = rs.getInt(1);
}
} catch (SQLException e) {
e.printStackTrace();
} finally{
DBConnection.close(rs); //关闭结果集对象
DBConnection.close(pstmt); //关闭预处理对象
DBConnection.close(conn); //关闭连接对象
}
return count;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Java Web投票系统(源码+数据库).zip
共415个文件
gif:162个
class:57个
java:57个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 1 下载量 45 浏览量
2022-04-11
20:08:02
上传
评论 3
收藏 17.05MB ZIP 举报
温馨提示
myecplise+tomcat+mysql或sql server 都支持。
资源推荐
资源详情
资源评论
收起资源包目录
Java Web投票系统(源码+数据库).zip (415个子文件)
VoteDAOImpl.class 6KB
VoteDAOImpl.class 6KB
VoteDAOImpl.class 6KB
VoteOptionDAOImpl.class 4KB
VoteOptionDAOImpl.class 4KB
VoteOptionDAOImpl.class 4KB
DoVoteAction.class 3KB
DoVoteAction.class 3KB
DoVoteAction.class 3KB
ShowVoteByChannelAction.class 3KB
ShowVoteByChannelAction.class 3KB
ShowVoteByChannelAction.class 3KB
VoteResultAction.class 3KB
VoteResultAction.class 3KB
VoteResultAction.class 3KB
ShowVoteAction.class 3KB
ShowVoteAction.class 3KB
ShowVoteAction.class 3KB
AddVoteAction.class 2KB
AddVoteAction.class 2KB
AddVoteAction.class 2KB
Page.class 2KB
Page.class 2KB
Page.class 2KB
DBConnection.class 2KB
DBConnection.class 2KB
DBConnection.class 2KB
DeleteVoteAction.class 2KB
DeleteVoteAction.class 2KB
DeleteVoteAction.class 2KB
PageUtil.class 1KB
PageUtil.class 1KB
PageUtil.class 1KB
VoteOption.class 1KB
VoteOption.class 1KB
VoteOption.class 1KB
VoteResult.class 1KB
VoteResult.class 1KB
VoteResult.class 1KB
Vote.class 935B
Vote.class 935B
Vote.class 935B
Channel.class 765B
Channel.class 765B
Channel.class 765B
VoteDAO.class 701B
VoteDAO.class 701B
VoteDAO.class 701B
VoteOptionDAOFactory.class 496B
VoteOptionDAOFactory.class 496B
VoteOptionDAOFactory.class 496B
VoteDAOFactory.class 460B
VoteDAOFactory.class 460B
VoteDAOFactory.class 460B
VoteOptionDAO.class 435B
VoteOptionDAO.class 435B
VoteOptionDAO.class 435B
.classpath 1KB
.classpath 1KB
.classpath 1KB
tab.css 3KB
tab.css 3KB
tab.css 3KB
style.css 1KB
style.css 1KB
style.css 1KB
main_08.gif 5KB
main_08.gif 5KB
main_08.gif 5KB
left_tree.gif 5KB
left_tree.gif 5KB
left_tree.gif 5KB
main_11.gif 4KB
main_11.gif 4KB
main_11.gif 4KB
main_12.gif 3KB
main_12.gif 3KB
main_12.gif 3KB
main_21.gif 2KB
main_21.gif 2KB
main_21.gif 2KB
main_31.gif 2KB
main_31.gif 2KB
main_31.gif 2KB
main_28.gif 2KB
main_28.gif 2KB
main_28.gif 2KB
main_31_1.gif 2KB
main_31_1.gif 2KB
main_31_1.gif 2KB
main_29_1.gif 2KB
main_29_1.gif 2KB
main_29_1.gif 2KB
main_26_1.gif 2KB
main_26_1.gif 2KB
main_26_1.gif 2KB
main_26.gif 2KB
main_26.gif 2KB
main_26.gif 2KB
main_06.gif 2KB
共 415 条
- 1
- 2
- 3
- 4
- 5
资源评论
- huangyanan1232022-12-27怎么能有这么好的资源!只能用感激涕零来形容TAT...
等天晴i
- 粉丝: 5870
- 资源: 10万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 10、安徽省大学生学科和技能竞赛A、B类项目列表(2019年版).xlsx
- 9、教育主管部门公布学科竞赛(2015版)-方喻飞
- C语言-leetcode题解之83-remove-duplicates-from-sorted-list.c
- C语言-leetcode题解之79-word-search.c
- C语言-leetcode题解之78-subsets.c
- C语言-leetcode题解之75-sort-colors.c
- C语言-leetcode题解之74-search-a-2d-matrix.c
- C语言-leetcode题解之73-set-matrix-zeroes.c
- 树莓派物联网智能家居基础教程
- YOLOv5深度学习目标检测基础教程
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功