Alguém pode me explicar o motivo desse erro? E o que eu fiz de errado pra tá dando isso?
Clinica:
package modelo;
public class Clinica {
private int id; private String cnpj; private String nome;
public int getId() { return id; }
public void setId(int id) { this.id = id; }
public String getCnpj() { return cnpj; }
public void setCnpj(String cnpj) { this.cnpj = cnpj; }
public String getNome() { return nome; }
public void setNome(String nome) { this.nome = nome; }
}
ClinicaDAO:
package modelo;
import java.sql.PreparedStatement;
public class ClinicaDAO extends DataBaseDAO {
public void inserir(Clinica clinica) throws Exception { this.conectar(); String sql = "INSERT INTO clinica (cnpj, nome) VALUES (?, ?)"; PreparedStatement pstm = conn.prepareStatement(sql); pstm.setString(1, clinica.getCnpj()); pstm.setString(2, clinica.getNome()); pstm.execute(); this.desconectar(); }
}
GerenciarClinica:
package controle;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import modelo.Clinica;
import modelo.ClinicaDAO;
public class GerenciarClinica extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet GerenciarClinica</title>"); out.println("</head>"); out.println("<body>");
/* ============================================================================= */
request.setCharacterEncoding(“UTF-8”);int id; String op = request.getParameter("op"); String cnpj = request.getParameter("cnpj"); String nome = request.getParameter("nome"); try { Clinica clinica = new Clinica(); if(op.equals("alterar") || op.equals("excluir")) { id = Integer.parseInt(request.getParameter("id")); clinica.setId(id); } clinica.setCnpj(cnpj); clinica.setNome(nome); ClinicaDAO clinicaDAO = new ClinicaDAO(); switch (op) { case "inserir": { if (cnpj.isEmpty() || cnpj.equals("")) { out.println("<script type='text/javascript'>"); out.println("alert('O campo 'CNPJ' deve ser preenchido!');"); out.println("hitory.back();"); out.println("</script>"); } else if (nome.isEmpty() || nome.equals("")) { out.println("<script type='text/javascript'>"); out.println("alert('O campo 'NOME' deve ser preenchido!');"); out.println("hitory.back();"); out.println("</script>"); } else { clinicaDAO.inserir(clinica); } } break; } } catch (Exception e) { out.println("<script type='text/javascript'>"); out.println("alert('Erro: " + e + "');"); out.println("hitory.back();"); out.println("</script>"); }
/* ============================================================================= */
out.println("");
out.println("");
}
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."> /** * Handles the HTTP <code>GET</code> method. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); }
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); }
/** * Returns a short description of the servlet. * * @return a String containing servlet description */ @Override public String getServletInfo() { return "Short description"; }// </editor-fold>
}
Erro: