jsp实现一个简单的投票系统

投票系统

实现结果图
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
(1)JDBC数据库连接工具类conn.java

package com.gx.bean;

import java.sql.*;

public class conn {
   
    public Connection getConn(){
   
        Connection conn = null;
        try {
   
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3308/manage","root","yww1352465324");
        } catch (ClassNotFoundException e) {
   
            e.printStackTrace();
        } catch (SQLException e){
   
            e.printStackTrace();
        }
        return conn;
    }
    public PreparedStatement prepare(Connection conn,String sql){
   
        PreparedStatement pstmt = null;
        try{
   
            if (conn != null) {
   
                pstmt = conn.prepareStatement(sql);
            }
        }catch (SQLException e){
   
            e.printStackTrace();
        }
        return  pstmt;
    }
    public Statement getStatement(Connection conn){
   
        Statement stmt = null;
        try{
   
            if (conn != null) {
   
                stmt = conn.createStatement();
            }
        }catch (SQLException e){
   
            e.printStackTrace();
        }
        return stmt;
    }
    public ResultSet getResultSet(Statement stmt,String sql){
   
        ResultSet rs = null;
        if(stmt!=null){
   
            try {
   
                rs = stmt.executeQuery(sql);
            } catch (SQLException throwables) {
   
                throwables.printStackTrace();
            }
        }
        return rs;
    }
    public void excuteUpdate(Statement stmt,String sql){
   
        if(stmt!=null){
   
            try {
   
                stmt.executeUpdate(sql);
            } catch (SQLException throwables) {
   
                throwables.printStackTrace();
            }
        }
    }
    public void close(Connection conn){
   
        if(conn!=null){
   
            try {
   
                conn.close();
            } catch (SQLException throwables) {
   
                throwables.printStackTrace();
            }
            conn=null;
        }
    }
    public void close(ResultSet rs){
   
        if(rs!=null){
   
            try {
   
                rs.close();
            } catch (SQLException throwables) {
   
                throwables.printStackTrace();
            }
            rs=null;
        }
    }
    public void close(Statement stmt){
   
        if(stmt!=null){
   
            try {
   
                stmt.close();
            } catch (SQLException throwables) {
   
                throwables.printStackTrace();
            }
            stmt=null;
        }
    }
}

(2)web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
</web-app>

(3)index.jsp

<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.Statement" %><%--
  Created by IntelliJ IDEA.
  User: 12526
  Date: 2021/1/15
  Time: 17:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>投票系统</title>
</head>
<body>
<jsp:useBean id="DB" class="com.gx.bean.conn" />
<center
  • 8
    点赞
  • 135
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 9
    评论
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

敲代码的洋葱头

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值