Statement psSelectRecord = null; ResultSet rsSelectRecord = null; String sqlSelectRecord = null; String check[] = request.getParameterValues("checkbox"); String subm = request.getParameter("submit"); Connection conn = (Connection) ses.getAttribute("conn"); try{ if(check != null ){ for(int i = 0; i< check.length;i++){ String x = check[i]; sqlSelectRecord ="DELETE FROM utilizador WHERE id='"+x+"'"; psSelectRecord=conn.createStatement(); psSelectRecord.executeUpdate(sqlSelectRecord); } } }catch (Exception e) { %> <script type="text/javascript">alert("Não selecionou nenhum user!") window.location= "javascript:history.back()";</script> </html> <% } %>
<pre lang="HTML">
<%@ page language="java" import="java.sql.*"%> <%@ page contentType="text/html; charset=UTF-8"%> <%@ include file="basedados.h" %> <% String usertype = (String) session.getAttribute("descricao"); Connection conn = (Connection) ses.getAttribute("conn"); try{ if( usertype.equals("presidente") ) { Statement psSelectRecord = null; ResultSet rsSelectRecord = null; String sql = null; sql = "SELECT * FROM utilizador"; psSelectRecord = conn.createStatement(); rsSelectRecord = psSelectRecord.executeQuery(sql); %> <html> <body> <form> <form action=apagar_utilizadorX.jsp" method="get"> <table border="1" cellspacing="1" cellpadding="1"> <tr> <th>ID</th> <th>Nome</th> <th>Login</th> <th>Password</th> <th>Tipo de Utilizador</th> <th>Telefone</th> <th>Morada</th> <th>Email</th> <th>Cartao Cidadao</th> <th>Cartao Caça</th> <th>NIF</th> <th></th> </tr> <% int cnt=1; while(rsSelectRecord.next()){ %> <tr> <td><%=rsSelectRecord.getString("id")%> </td> <td><%=rsSelectRecord.getString("nome")%> </td> <td><%=rsSelectRecord.getString("login")%> </td> <td><%=rsSelectRecord.getString("password")%> </td> <td><%=rsSelectRecord.getString("utilizadortipo")%> </td> <td><%=rsSelectRecord.getString("telefone")%> </td> <td><%=rsSelectRecord.getString("morada")%> </td> <td><%=rsSelectRecord.getString("email")%> </td> <td><%=rsSelectRecord.getString("cartaoCidadao")%> </td> <td><%=rsSelectRecord.getString("cartaoCaca")%> </td> <td><%=rsSelectRecord.getString("nif")%> </td> <td><input type="checkbox" name="checkbox" value="<%=cnt%>"><br></td> </tr> <% cnt++; } %> <input type="submit" name ="submit" value="Eliminar!"> </table> <form/> </body> </html> <% } }catch (Exception e) { %> <script type="text/javascript">alert("Acesso Restrito") window.location= "javascript:history.back()";</script> </html> <% } %>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)