一起学习
先建一个数据库,其中有一个表count,此表只须一条记录三个字段(good,normal,bad)
再建两个文件(select.html和diaocha.jsp)
select.html(提供选择)
--------------------------------------------
diaocha.jsp(用来统计调查情况,并以条形显示结果)
----------------------------------------------
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*" %>
<%
String select=request.getParameter("diaocha");
byte[] t=select.getBytes("ISO8859_1");
select=new String(t);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("Jdbc:odbc:diaocha");
Statement smt=con.createStatement();
String sql;
out.println("
" "投票结果如下:" "
");
if (select.equals("good"))
{
sql="update diaocha set good=good 1";
smt.executeUpdate(sql);
}
else if(select.equals("normal"))
{
sql="update diaocha set normal=normal 1";
smt.executeUpdate(sql);
}
else
{
sql="update diaocha set bad=bad 1";
smt.executeUpdate(sql);
}
sql="select * from diaocha";
ResultSet rs=smt.executeQuery(sql);
rs.next();
int good=rs.getInt(1),normal=rs.getInt(2),bad=rs.getInt(3),total=good normal bad;
out.println("
");
out.println("" "好的:" "");
out.println("");
out.println(good "人" "
");
out.println("" "一般:" "");
out.println("");
out.println(normal "人" "
");
out.println("" "差的:" "");
out.println("");
out.println(bad "人" "
");
out.println("");
out.println("总共有" total "人投票" "
");
out.println("");
con.close();
%>
下载本文示例代码
小小调查通小小调查通小小调查通小小调查通小小调查通小小调查通小小调查通小小调查通小小调查通小小调查通小小调查通小小调查通
阅读(103) | 评论(0) | 转发(0) |