package dao;
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 entity.Poll;
public class PollDao extends BaseDao{
//查询所有投票信息,返回一个集合对象
public Connection conn;
public PreparedStatement pStatement;
public ResultSet resultSet;
public List<Poll>getAllPoll(){
List<Poll>polList=new ArrayList<Poll>();
String sql="select * from poll";
try {
conn=getConnection();
pStatement=conn.prepareStatement(sql);
resultSet=pStatement.executeQuery();
while(resultSet.next()){
Poll poll=new Poll();
poll.setId(resultSet.getInt("id"));
poll.setPollname(resultSet.getString("pollname"));
poll.setPollcount(resultSet.getInt("pollcount"));
polList.add(poll);
}
} catch (Exception e) {
// TODO: handle exception
}
finally
{
CloseAllConn(connection, pStatement, resultSet);
}
return polList;
}
//根据语言id查找投票的总数
public int getPollCountById(int id){
int result=-1;
String sqlString="select pollcount from poll where id="+id;
try {
conn = getConnection();
pStatement =conn.prepareStatement(sqlString);
resultSet =pStatement.executeQuery();
while(resultSet.next()){
result = resultSet.getInt("pollcount");
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{CloseAllConn(connection, pStatement, resultSet);}
return result;
}
public void modifyPoll(int id,int pollCount){
String sqlString="update poll set pollcount =" + pollCount +" where id ="+id;
try {
conn=getConnection();
pStatement=conn.prepareStatement(sqlString);
pStatement.executeUpdate();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{CloseAllConn(connection, pStatement, resultSet);}
}
//添加一条投票 根据传入的语言id
public boolean pollIng(int pId){
String sqlString="update poll set pollcount = pollcount "+"+"+ 1 +"where id = "+pId;
boolean res=false;
try {
conn = getConnection();
pStatement = conn.prepareStatement(sqlString);
int result = pStatement.executeUpdate();
if(result!=0){
res=true;
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
CloseAllConn(conn, pStatement, resultSet);
}
return res;
}
}
javascript的单选按钮表单验证 + jsp页面投票应用
3星 · 超过75%的资源 需积分: 10 3 浏览量
2009-12-01
14:05:31
上传
评论
收藏 683KB RAR 举报
yiptung
- 粉丝: 0
- 资源: 1
最新资源
- python-leetcode面试题解之第157题用Read4读取N个字符-题解.zip
- python-leetcode面试题解之第156题上下翻转二叉树-题解.zip
- python-leetcode面试题解之第155题最小栈-题解.zip
- python-leetcode面试题解之第153题寻找旋转排序数组中的最小值-题解.zip
- python-leetcode面试题解之第152题乘积最大子数组-题解.zip
- python-leetcode面试题解之第151题反转字符串中的单词-题解.zip
- python-leetcode面试题解之第150题逆波兰表达式求值-题解.zip
- python-leetcode面试题解之第149题直线上最多的点数-题解.zip
- python-leetcode面试题解之第148题排序链表-题解.zip
- python-leetcode面试题解之第147题对链表进行插入排序-题解.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈