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;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Javaweb企业管理系统_完整源码+Mysql文件 (137个子文件)
VoteDAOImpl.class 6KB
VoteOptionDAOImpl.class 4KB
DoVoteAction.class 3KB
ShowVoteByChannelAction.class 3KB
VoteResultAction.class 3KB
ShowVoteAction.class 3KB
AddVoteAction.class 2KB
Page.class 2KB
DBConnection.class 2KB
DeleteVoteAction.class 2KB
PageUtil.class 1KB
VoteOption.class 1KB
VoteResult.class 1KB
Vote.class 935B
Channel.class 765B
VoteDAO.class 701B
VoteOptionDAOFactory.class 496B
VoteDAOFactory.class 460B
VoteOptionDAO.class 435B
.classpath 1KB
tab.css 3KB
style.css 1KB
main_08.gif 5KB
left_tree.gif 5KB
main_11.gif 4KB
main_12.gif 3KB
main_21.gif 2KB
main_31.gif 2KB
main_28.gif 2KB
main_31_1.gif 2KB
main_29_1.gif 2KB
main_26_1.gif 2KB
main_26.gif 2KB
main_06.gif 2KB
main_07.gif 2KB
tab_05.gif 1KB
tab_03.gif 1KB
tab_07.gif 1KB
005.gif 1024B
g_page.gif 1024B
back.gif 749B
next.gif 745B
last.gif 741B
go.gif 736B
first.gif 736B
main_45.gif 726B
main_01.gif 682B
main_09.gif 617B
311.gif 608B
a.gif 556B
main_23.gif 420B
main_16.gif 405B
main_49.gif 400B
083.gif 341B
114.gif 337B
main_51.gif 322B
main_47.gif 309B
main_14.gif 309B
002.gif 308B
tab_14.gif 263B
001.gif 213B
arrow_082.gif 181B
tab_20.gif 164B
main_04.gif 140B
tab_22.gif 131B
037.gif 118B
tab_12.gif 112B
tab_16.gif 112B
a1.gif 100B
main_38.gif 97B
main_40.gif 91B
main_42.gif 87B
main_18.gif 84B
tab_21.gif 83B
010.gif 65B
spacer.gif 43B
left.html 3KB
down.html 1KB
center.html 1016B
top.html 720B
xwork-2.1.2.jar 2.18MB
jfreechart-1.0.9.jar 1.23MB
freemarker-2.3.13.jar 850KB
struts2-core-2.1.6.jar 719KB
mysql-connector-java-5.0.8-bin.jar 528KB
jcommon-1.0.12.jar 301KB
ognl-2.6.11.jar 164KB
commons-fileupload-1.2.1.jar 56KB
commons-logging-1.0.4.jar 37KB
struts2-jfreechart-plugin-2.1.6.jar 10KB
VoteDAOImpl.java 7KB
VoteOptionDAOImpl.java 4KB
DoVoteAction.java 2KB
ShowVoteByChannelAction.java 2KB
Page.java 2KB
VoteResultAction.java 2KB
DBConnection.java 2KB
ShowVoteAction.java 2KB
AddVoteAction.java 2KB
PageUtil.java 2KB
共 137 条
- 1
- 2
资源评论
- 长春藤伊甸园2022-05-11非常差不要下载
qq365281664
- 粉丝: 13
- 资源: 21
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功