zoukankan      html  css  js  c++  java
  • 教师投票系统(JSP+MySQL)

    display.jsp

    <%@ page language="java" import="java.sql.*" pageEncoding="gb2312"%>

     

    <html>

      

      

      <body>

     

            <table align="center">

            <caption>欢迎给老师投票</caption>

            <tr bgcolor="yellow">

            <td>编号</td>

             <td>姓名</td>

              <td>得票数</td>

               <td>投票</td>

            </tr>

         

            

            <%

            

                Class.forName("com.mysql.jdbc.Driver");

     

                Connection conn=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/school","root","laifu1990");

     

                Statement stat=conn.createStatement();

                 String sql="select teacherno,teachername,vote from t_vote";

                 ResultSet rs=stat.executeQuery(sql);

                 while(rs.next())

                 {

                   String teacherno=rs.getString("teacherno");

                   String teachername=rs.getString("teachername");

                   int vote=rs.getInt("vote");

                   

                %>

                 

           

             <tr bgcolor="pink">

             <td><%=teacherno %></td>

             <td><%=teachername %></td>

             <td><img  src="img/bar.jpg" width="<%=vote %>>" height="10">

             <%=vote%></td>

             <td><a href="vote.jsp?teacherno=<%=teacherno%>">投票</a></td>

             </tr>

              <%

                }

                   

              stat.close();

              conn.close();

              %>

              </table>

      </body>

    </html>

    vote.jsp

    <%@ page language="java" import="java.sql.*" pageEncoding="gb2312"%>

     

      <html>

      

      

      <body>

        <%

           String teacherno = request.getParameter("teacherno");

           Class.forName("com.mysql.jdbc.Driver");

     

          Connection conn=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/school","root","laifu1990");

     

           String sql="update t_vote set vote=vote+1 where teacherno=?";

           PreparedStatement ps=conn.prepareStatement(sql);

           ps.setString(1, teacherno);

           ps.executeUpdate();

           ps.close();

           conn.close();

           

         %>

        <jsp:forward page="display.jsp"></jsp:forward>

      </body>

    </html>

     

     

  • 相关阅读:
    【SQL】oralce中使用group by和case when按照条件求和
    【SQL】ORACLE在sqlplus中使用spool方式生成建表语句
    【SQL】将特定的元素按照自己所需的位置排序
    【LeetCode刷题】SQL-Second Highest Salary 及扩展以及Oracle中的用法
    【LeetCode刷题】SQL-Combine Two Tables
    CSDN无故封我账号,转战博客园。
    Visual Studio 代码管理器svn插件下载
    Geoserver的跨域问题
    Jmeter+Ant+jenkins实现api自动化测试的持续集成
    python编程中的并发------多线程threading模块
  • 原文地址:https://www.cnblogs.com/laifu/p/3380687.html
Copyright © 2011-2022 走看看