4
Language: Java Server: Apache Tomcat. Ambient: Eclipse.
I am following the Caelum Workbook of the course FJ21 - Web Development with Java. I created a form but at the time of recording it presents the following error:
HTTP Status 500 - Servlet Execution threw an Exception
type Exception report
message Servlet Execution threw an Exception
The server encountered an Internal error that prevented it from fulfilling this request.
Exception
javax.servlet.Servletexception: Servlet Execution threw an Exception org.apache.Tomcat.websocket.server.WsFilter.doFilter(Wsfilter.java:53) root cause
java.lang.Error: Unresolved Compilation problem: Unhandled Exception type Sqlexception
br.com.Caelum.jdbc.dao.ContactoDAO. (Contactodao.java:19)
br.com.Caelum.agenda.Servlet.AdicionaContactsServlet.service(Addresscontact.java:46) javax.servlet.http.HttpServlet.service(Httpservlet.java:729) org.apache.Tomcat.websocket.server.WsFilter.doFilter(Wsfilter.java:53) note The full stack trace of the root cause is available in the Apache Tomcat/9.0.0.M15 logs.
Follow the code of the Contactodao class:
public class ContatoDAO {
private Connection connection;
public ContatoDAO() {
try {
this.connection = new ConnectionFactory().getConnection();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void adiciona(Contato contato) {
String sql = "insert into contatos (nome, email, endereco, dataNascimento) values (?,?,?,?)";
try {
PreparedStatement stmt = connection.prepareStatement(sql);
stmt.setString(1, contato.getNome());
stmt.setString(2, contato.getEmail());
stmt.setString(3, contato.getEndereco());
stmt.setDate(4, new Date(contato.getDataNascimento().getTimeInMillis()));
stmt.execute();
stmt.close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
Class Contact:
public class Contato {
private Long id;
private String nome;
private String email;
private String endereco;
private Calendar dataNascimento;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getEndereco() {
return endereco;
}
public void setEndereco(String endereco) {
this.endereco = endereco;
}
public Calendar getDataNascimento() {
return dataNascimento;
}
public void setDataNascimento(Calendar dataNascimento) {
this.dataNascimento = dataNascimento;
}
}
Put the class "Contact"
– mau humor
I updated the post with the contact class.
– Yuri Nascimento