标题:各位大哥,请教一下,怎样添加删除项,达到删除投票项的目的,(那又如何进 ...
取消只看楼主
yuweilong012
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2010-12-4
 问题点数:0 回复次数:2 
各位大哥,请教一下,怎样添加删除项,达到删除投票项的目的,(那又如何进行添加项呢)
survey.jsp页面
<%@page contentType="text/html;charset=GBK"%>
<%@page language="java" import="java.sql.*"%>
<html>
<head>
<title>网上调查表</title>
</head>
<%
  try{
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      }
      catch(ClassNotFoundException e){}
try{
    Connection con=DriverManager.getConnection("jdbc:odbc:test");
Statement sql=con.createStatement();
ResultSet rs=sql.executeQuery("select*from vote");

%>
<body bg="#FFCCCC">
<center>
<font face="隶书" size="5">调查问卷,请你投票:</font><br>
<font face="隶书" size="5">你认为世界杯哪只球队能够夺冠</font>
<form action="vote.jsp">
<Table width="114" border bgcolor="#FFFFCC">
<%
while (rs.next()) {
%>
<tr>
<td>
<input type="radio" name="type" value=<%=rs.getInt("id")%>>
<%=rs.getString("country")%>
</td>
</tr>
<%
}
rs.close();
con.close();
} catch (SQLException e1) {
}
%>
<tr align="center">
<td>
<input type="submit" value="投票">
</td>
</tr>
</table>
</form>
<br>
<A href="view.jsp">查看投票</A>
</center>
</body>
</html>
投票处理页面
vote.jsp
<%@page contentType="text/html;charset=GBK"%>
<%@page import="java.sql.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){}
try{
Connection con=DriverManager.getConnection("jdbc:odbc:test");
Statement sql=con.createStatement();
ResultSet rs;
String rb=request.getParameter("type");
if(rb!=null&&rb!=""){
String condition="Update vote Set numb=numb+1 where id=" +rb;
sql.executeUpdate(condition);
}
con.close();
}
catch(SQLException event){}
%>  
<jsp:forward page="view.jsp"/>
投票结果显示
view.jsp
<%@ page contentType="text/html;charset=GB2312"%>
<%@page import="java.sql.*" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>Connect SQL Server Test</title>
    <style type="text/css">
        body{margin:0px auto;padding:0px;font-size:12px;text-align:center;}
        div,h3{margin:0px;padding:0px;}
        #body{margin:10px auto;padding:10px;width:400px;border:1px solid #EEEEEE;background:#F7F7F7;line-height:22px;text-align:left;}
        #body h3{color:#CC0000;margin-bottom:10px;border-bottom:2px solid #CC0000;text-indent:10px;font-size:14px;}
        #body strong{border-bottom:1px solid #888888;}
    </style>
  </head>
  
  <body>
      <div id="body">
      <h3>投票数为:</h3>
    <%
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection conn = DriverManager.getConnection("jdbc:odbc:test");
        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT * FROM vote");
        out.println("<strong><font color=\"#008800\">id</font>  --  <font color=\"#0000FF\">&nbsp;content&nbsp;</font>  -- <font color=\"#CC0000\">&nbsp;numd</font></strong><br>");
           while(rs.next()){
            out.println("<font color=\"#008800\">" + rs.getString("id") + "</font>  --------  <font color=\"#0000FF\">" + rs.getString("country") + "</font>  --------  <font color=\"#CC0000\">" + rs.getString("numb") + "</font><br>");
        }
        rs.close();
        stmt.close();
        conn.close();
    %>
    </div>
    <a href="survey.jsp">返回投票</a>
   
  
  </body>
</html>


[ 本帖最后由 yuweilong012 于 2010-12-5 09:30 编辑 ]
搜索更多相关主题的帖子: 目的 投票 删除 
2010-12-05 09:20
yuweilong012
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2010-12-4
得分:0 
不好意思,我说错了,应该是删除投票项,获取id就可以删除行。
2010-12-05 09:29
yuweilong012
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2010-12-4
得分:0 
各位高手,请告诉我怎样做
2010-12-05 09:30



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-327942-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.326375 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved