<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.sql.*,org.opencms.main.*, java.text.*"%> <%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <% String id = pageContext.getAttribute("id").toString() != null ? pageContext.getAttribute("id").toString() : "0"; int idINT = 0; //wwwd.almg.gov.br/system/modules/br.gov.almg.site.portal/templates/participe/enquete_aleijadinho/deletar_resposta.jsp?id=x %> <% Connection con = OpenCms.getSqlManager().getConnection("sic"); PreparedStatement stmt =null; //Query String queryPre = "DELETE FROM tvoto_enquete_almg WHERE id_resposta = ?"; String query = "DELETE FROM tresposta_enquete_almg WHERE id = ?"; try{ idINT = Integer.parseInt(id); if(!id.equals("0")){ try{ //1.a) Deletando todos os votos da resposta stmt = con.prepareStatement(queryPre); stmt.setInt(1, idINT); boolean r = stmt.execute(); //1.b) Fechando conexao stmt.close(); //2.a) Deletando resposta stmt = con.prepareStatement(query); stmt.setInt(1, idINT); r = stmt.execute(); //2.b) Fechando conexao stmt.close(); }catch (SQLException ex) { ex.printStackTrace(); out.print(ex.getMessage()); }finally{ //rs.close(); stmt.close(); con.close(); } }else{ out.print("id igual a 0"); } }catch(NumberFormatException erro){ out.print("ID Não identificado"); } //response.sendRedirect(gotoPage); %>