Click here to Skip to main content
15,795,793 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
hi, my JSP code doesn't work... i cant find a solution for this..

my checkbox are select but doesn't do the SQL part.. Take a look pls
JavaScript


	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">

ASP.NET
<%@ 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")%>&nbsp;</td>
                <td><%=rsSelectRecord.getString("nome")%>&nbsp;</td>
                <td><%=rsSelectRecord.getString("login")%>&nbsp;</td>
				<td><%=rsSelectRecord.getString("password")%>&nbsp;</td>
                <td><%=rsSelectRecord.getString("utilizadortipo")%>&nbsp;</td>
                <td><%=rsSelectRecord.getString("telefone")%>&nbsp;</td>
				<td><%=rsSelectRecord.getString("morada")%>&nbsp;</td>
				<td><%=rsSelectRecord.getString("email")%>&nbsp;</td>
				<td><%=rsSelectRecord.getString("cartaoCidadao")%>&nbsp;</td>
				<td><%=rsSelectRecord.getString("cartaoCaca")%>&nbsp;</td>
				<td><%=rsSelectRecord.getString("nif")%>&nbsp;</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>
	<%
	}
	%>


What I have tried:

My error is on connection with database .. i know it but i cant find a solution
Posted
Comments
Sergey Alexandrovich Kryukov 10-Jun-16 14:43pm    
What does it mean: "my checkbox are select but doesn't do the SQL part"?
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900