资源简介
JSP实现 在线投票系统
在线投票系统,该系统可以对投票数量进行累加、查询统计票数等操作。
操作注意事项
1.在进行投票操作时,一个小时内只能投一次票。
在线投票系统,该系统可以对投票数量进行累加、查询统计票数等操作。
操作注意事项
1.在进行投票操作时,一个小时内只能投一次票。
代码片段和文件信息
package com.database;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
import com.valuebean.UserSingle;
import com.valuebean.voteSingle;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
public class DB {
private String className;
private String url;
private String username;
private String password;
private Connection con;
private Statement st;
private ResultSet res;
public DB() {
className=“com.mysql.jdbc.Driver“;
url=“jdbc:mysql://localhost:3306/votedb“;
username = “root“;
password = “3.14159“;
}
public void loadDriver() {
try {
Class.forName(className);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
System.out.println(“加载数据库驱动失败!“);
e.printStackTrace();
}
}
public void getConnection() {
loadDriver();
try {
con = (Connection) DriverManager.getConnection(url username password);
} catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println(“连接数据库失败!“);
e.printStackTrace();
}
}
public void getStatement() {
getConnection();
try {
st = (Statement) con.createStatement();
} catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println(“获取statement对象失败“);
e.printStackTrace();
}
}
public void getResultSet(String sql) {
if(sql != null && !sql.equals(““)) {
getStatement();
try {
res = st.executeQuery(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println(“查询数据库失败!“);
e.printStackTrace();
}
}
}
public void closed() {
try {
if(res != null) {
res.close();
}
if(con != null) {
con.close();
}
if(st != null) {
st.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println(“关闭数据库失败!“);
e.printStackTrace();
}
}
public int update(String sql) {
int i = -1;
if(sql != null && !sql.equals(““)) {
getStatement();
try {
i = st.executeUpdate(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println(“数据库更新失败!“);
e.printStackTrace();
}finally {
closed();
}
}
return i;
}
public ArrayList getVotes(){
String sql = “select * from vote“;
getResultSet(sql);
ArrayList votes = new ArrayList();
try {
while(res.next()) {
voteSingle v = new voteSingle();
v.setId(res.getString(1));
v.settitle(res.getString(2));
v.setNum(res.getString(3));
votes.add(v);
}
res.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return votes;
}
public ArrayList getUsers(){
String sql = “select * from users“;
getResultSet(sql);
ArrayList users = new ArrayList();
try {
wh
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-04-17 17:11 VoteDemo\
文件 840 2018-04-17 22:01 VoteDemo\.classpath
文件 908 2018-04-17 17:10 VoteDemo\.project
目录 0 2018-04-17 17:10 VoteDemo\.settings\
文件 567 2018-04-17 17:10 VoteDemo\.settings\.jsdtscope
文件 364 2018-04-17 17:10 VoteDemo\.settings\org.eclipse.jdt.core.prefs
文件 476 2018-04-17 17:10 VoteDemo\.settings\org.eclipse.wst.common.component
文件 305 2018-04-17 17:10 VoteDemo\.settings\org.eclipse.wst.common.project.facet.core.xm
文件 49 2018-04-17 17:10 VoteDemo\.settings\org.eclipse.wst.jsdt.ui.superType.container
文件 6 2018-04-17 17:10 VoteDemo\.settings\org.eclipse.wst.jsdt.ui.superType.name
目录 0 2018-04-17 17:10 VoteDemo\build\
目录 0 2018-04-17 22:01 VoteDemo\build\classes\
目录 0 2018-04-17 22:01 VoteDemo\build\classes\com\
目录 0 2018-04-17 22:01 VoteDemo\build\classes\com\databa
文件 5385 2018-04-18 10:42 VoteDemo\build\classes\com\databa
目录 0 2018-04-17 22:01 VoteDemo\build\classes\com\toolbean\
文件 1579 2018-04-18 00:03 VoteDemo\build\classes\com\toolbean\MyTool.class
目录 0 2018-04-17 22:01 VoteDemo\build\classes\com\valuebean\
文件 914 2018-04-17 22:01 VoteDemo\build\classes\com\valuebean\UserSingle.class
文件 891 2018-04-17 22:01 VoteDemo\build\classes\com\valuebean\voteSingle.class
目录 0 2018-04-17 17:11 VoteDemo\Sql\
文件 464 2018-04-18 01:00 VoteDemo\Sql\init.sql
目录 0 2018-04-17 19:30 VoteDemo\src\
目录 0 2018-04-17 19:30 VoteDemo\src\com\
目录 0 2018-04-17 17:46 VoteDemo\src\com\databa
文件 4469 2018-04-18 10:42 VoteDemo\src\com\databa
目录 0 2018-04-17 19:30 VoteDemo\src\com\toolbean\
文件 873 2018-04-18 00:03 VoteDemo\src\com\toolbean\MyTool.java
目录 0 2018-04-17 17:44 VoteDemo\src\com\valuebean\
文件 449 2018-04-17 17:43 VoteDemo\src\com\valuebean\UserSingle.java
文件 441 2018-04-17 17:45 VoteDemo\src\com\valuebean\voteSingle.java
............此处省略13个文件信息
相关资源
- 运用jsp实现的购物车模块
- javabean+servlet+jsp实现圆的面积和周长计
- SSM框架结合html和jsp实现简单的查询功
- jsp实现登录功能
- 使用MongoDB和JSP实现一个简单的购物车
- 简单的jdbc+mysql+jsp实现的增删改查
- JSP实现web网页访问次数
- JSP实现登录注册连接MySql数据库-初学
- JSP实现班级通讯录系统[源码文档]
- jsp实现简易购物车
- jsp实现在线阅读系统
- JSP、Servlet在线投票系统
- Jsp实现博客系统,博文增删改查,添
- JSP实现将数据分页显示类
- jsp实现交友网络
- jsp实现的简单员工加班管理系统
- jsp实现上传图片功能
- jsp实现的Email邮件发送
- jsp实现分页.zip
- 从数据库动态生成树形菜单的JSP实现
- JSP实现购物商城包括购物车
- 邮局订报管理系统(JSP实现)
- java web项目源码:在线投票系统(源码
- JSP实现网上购物(access数据库)
- jsp实现登陆操作(带验证码)
- zk+jsp实现登录、注册、修改密码小
- 购书网站用 javabean+servlet+jsp实现
- 在线投票系统毕业论文
- jsp实现分页案例
-
xm
l+jsp实现简单留言板
评论
共有 条评论