编程语言

img blueis

小弟实在太郁闷了!!请各位高手指点!!!

发表于2004/10/29 22:59:00  799人阅读

郁闷啊!!!为什么不管点击哪一个删除,删除的都是第一个,为什么啊!!!这个问题找了很长时间但是都没有找到.
请各位高手帮忙 小弟先谢谢了!!
文件名:delete1.jsp
<%@page contentType="text/html;charset=GB2312"%>
<%@page import="java.sql.*"%>
<html>
<head>
<script language="JavaScript">
<!--
     function sure()
     {
     alert("确定删除");
     }
-->
</script>
</head>
<body>
<% String delete ;
  String sure="sure()";
  int i;
  delete=response.encodeURL("delete.jsp");
  String number=request.getParameter("number");
        if(number==null)
        {number="";
        }
   byte b[]=number.getBytes("ISO-8859-1");
   number=new String(b);
   String name=request.getParameter("name");
          if(name==null)
          {name="";
          }
   byte n[]=name.getBytes("ISO-8859-1");
   name=new String(n);
   String department=request.getParameter("department");
          if(department==null)
          {department="";
          }
   byte d[]=department.getBytes("ISO-8859-1");
   department=new String(d);
   Connection con=null;
   Statement sql=null;
   ResultSet rs=null;
   try{
       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
       }
   catch(ClassNotFoundException e){}
    try
      {
       con=DriverManager.getConnection("jdbc:odbc:moon","","");
       sql=con.createStatement();
       String condition="select * from student where 学号 like'%"+number+"%'or 姓名 like'%"+name+"%'or 专业 like'%"+department+"%'";
       rs=sql.executeQuery(condition);
       %>
    <table width="1427" height="68" border="1" cellpadding="0" cellspacing="0" bordercolor="#0000FF" bgcolor="#FFFFFF">
  <tr bordercolor="#0000FF">
    <td height="30"><div align="center" class="style2">学  号</div></td>
    <td height="30"><div align="center" class="style2">姓  名</div></td>
    <td height="30"><div align="center" class="style2">性  别</div></td>
    <td height="30"><div align="center" class="style2">民  族</div></td>
    <td height="30"><div align="center" class="style2">出生日期</div></td>
    <td height="30"><div align="center" class="style2">政治面貌</div></td>
    <td height="30"><div align="center" class="style2">籍  贯</div></td>
    <td height="30"><div align="center" class="style2">家庭住址</div></td>
    <td height="30"><div align="center" class="style2">电  话</div></td>
    <td height="30"><div align="center" class="style2">毕业单位地址</div></td>
    <td height="30"><div align="center" class="style2">入学时间</div></td>
    <td height="30"><div align="center" class="style2">语  种</div></td>
    <td height="30"><div align="center" class="style2">年  级</div></td>
    <td height="30"><div align="center" class="style2">专  业</div></td>
    <td height="30"><div align="center" class="style2">指导教师</div></td>
    <td height="30"><div align="center" class="style2">单位地址</div></td>
    <td height="30"><div align="center" class="style2">学  历</div></td>
    <td height="30"><div align="center" class="style2">社会关系</div></td>
    <td height="30"><div align="center" class="style2">研究成果</div></td>
    <td height="30"><div align="center" class="style2">个人简历</div></td>
    <td height="30"><div align="center">删  除</div></td>
  </tr>
  <%
       while(rs.next())
            {
             String id=rs.getString(1);
             %>
             <tr bordercolor="#0000FF">
             <td height="30"><div align="center">&nbsp<%=id%></div></td>
             <td height="30"><div align="center">&nbsp<%=rs.getString(2)%></div></td>
             <td height="30"><div align="center">&nbsp<%=rs.getString(3)%></div></td>
             <td height="30"><div align="center">&nbsp<%=rs.getString(4)%></div></td>
             <td height="30"><div align="center">&nbsp<%=rs.getString(5)%></div></td>
             <td height="30"><div align="center">&nbsp<%=rs.getString(6)%></div></td>
             <td height="30"><div align="center">&nbsp<%=rs.getString(7)%></div></td>
             <td height="30"><div align="center">&nbsp<%=rs.getString(8)%></div></td>
             <td height="30"><div align="center">&nbsp<%=rs.getString(9)%></div></td>
             <td height="30"><div align="center">&nbsp<%=rs.getString(10)%></div></td>
             <td height="30"><div align="center">&nbsp<%=rs.getString(11)%></div></td>
             <td height="30"><div align="center">&nbsp<%=rs.getString(12)%></div></td>
             <td height="30"><div align="center">&nbsp<%=rs.getString(13)%></div></td>
             <td height="30"><div align="center">&nbsp<%=rs.getString(14)%></div></td>
             <td height="30"><div align="center">&nbsp<%=rs.getString(15)%></div></td>
             <td height="30"><div align="center">&nbsp<%=rs.getString(16)%></div></td>
             <td height="30"><div align="center">&nbsp<%=rs.getString(17)%></div></td>
             <td height="30"><div align="center">&nbsp<%=rs.getString(18)%></div></td>
             <td height="30"><div align="center">&nbsp<%=rs.getString(19)%></div></td>
             <td height="30"><div align="center">&nbsp<%=rs.getString(20)%></div></td>
             <% String s1="<Form name=from action="+delete2+" method=get>";
             String s2="<input type=hidden name=id value="+id+">";
             String s3="<input type=submit  value=删除 onclick="+sure+"></from>";
             String s=s1+s2+s3;
             out.print("<td>"+s+"<td>");
             out.print("+id+");
             %>
             </tr>
          <%
            }
            %>
</table>
        <%  
          con.close();
       }
  catch(SQLException e){out.print("wrong");}    
%>  
</body>
</html>
文件名:delete2.jsp
<%@ page contentType="text/html;charset=GBK"%>
<%@ page import="java.sql.*"%>
<html>
  <body>
    <%
    String number=request.getParameter("id");
           if(number==null)
              {number="";
              }
    byte n[]=number.getBytes("ISO-8859-1");
    number=new String(n);
    Connection con;
    Statement  sql;
    ResultSet  rs;
    try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    }
    catch(ClassNotFoundException event){}
    try
    {
    con=DriverManager.getConnection("jdbc:odbc:moon","","");
    sql=con.createStatement();
    String deletall="DELETE FROM student WHERE 学号='"+number+"'";
    sql.executeUpdate(deletall);
    out.print("删除成功");
     }
    catch(SQLException event)
          {out.print("event");
          }
    %>
   </body>
</html>
阅读全文
0 0

相关文章推荐

img
取 消
img