Estou com erro 500, devido a compilação, tenho meus métodos getter and setters, construtores definidos, criei um página em jsp, porém o parâmetro que possui para caracter não sei ao certo se seria esse, pois está com mensagem de erro de “contructor not defined”
package br.com.escolamaxima.modelo;
import java.util.Calendar;
public class Aluno {
private int id;
private String nome;
private String profissao;
private Calendar nascimento;
private char sexo;
private double peso;
private double altura;
private String nacionalidade;
private int cursoPreferido;
public Aluno(String nome, String profissao, Calendar nascimento, char sexo,
double peso, double altura,
String nacionalidade, int cursopreferido) {
this.nome = nome;
this.profissao = profissao;
this.nascimento = nascimento;
this.sexo = sexo;
this.peso = peso;
this.altura = altura;
this.nacionalidade = nacionalidade;
this.cursoPreferido = cursopreferido;
}
public Aluno() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getProfissao() {
return profissao;
}
public void setProfissao(String profissao) {
this.profissao = profissao;
}
public Calendar getNascimento() {
return nascimento;
}
public void setNascimento(Calendar nascimento) {
this.nascimento = nascimento;
}
public char getSexo() {
return sexo;
}
public void setSexo(char sexo) {
this.sexo = sexo;
}
public double getPeso() {
return peso;
}
public void setPeso(double peso) {
this.peso = peso;
}
public double getAltura() {
return altura;
}
public void setAltura(double altura) {
this.altura = altura;
}
public String getNacionalidade() {
return nacionalidade;
}
public void setNacionalidade(String nacionalidade) {
this.nacionalidade = nacionalidade;
}
public int getCursoPreferido() {
return cursoPreferido;
}
public void setCursoPreferido(int cursoPreferido) {
this.cursoPreferido = cursoPreferido;
}
}
//////----------------------------------
package br.com.excolamaxima.dao;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import br.com.escolamaxima.modelo.Aluno;
public class AlunoDao {
private Connection connection;
public AlunoDao() throws ClassNotFoundException {
this.connection = new ConnectionFactory().getConnection();
}
public void adiciona(Aluno aluno) {
String sql = "insert into gafanhotos (nome, profissao, nascimento,"
+ " sexo, peso, altura, nacionalidade, cursopreferido) values (?,?,?,?,?,?,?,?)";
try (PreparedStatement stmt = (PreparedStatement) connection.prepareStatement(sql)) {
stmt.setString(1, aluno.getNome());
stmt.setString(2, aluno.getProfissao());
stmt.setDate(3, new Date(aluno.getNascimento().getTimeInMillis()));
stmt.setString(4, String.valueOf(aluno.getSexo()));
stmt.setDouble(5, aluno.getPeso());
stmt.setDouble(6, aluno.getAltura());
stmt.setInt(7, aluno.getCursoPreferido());
stmt.executeUpdate();
} catch (SQLException ex) {
throw new RuntimeException(ex);
} // fim try
}// fim adiciona
public List<Aluno> getLista() {
String sql = "select * from gafanhotos";
List<Aluno> alunos = new ArrayList();
try (PreparedStatement stmt = connection.prepareStatement(sql)) {
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
Aluno aluno = new Aluno();
aluno.setId(rs.getInt("id"));
aluno.setNome(rs.getString("nome"));
aluno.setProfissao(rs.getString("profissao"));
Calendar data = Calendar.getInstance();
data.setTime(rs.getDate("nascimento"));
aluno.setNascimento(data);
aluno.setSexo(rs.getString("sexo").charAt(0));
aluno.setPeso(rs.getDouble("peso"));
aluno.setAltura(rs.getDouble("altura"));
aluno.setCursoPreferido(rs.getInt("cursoPreferido"));
alunos.add(aluno);
} // fim while
} catch (SQLException ex) {
throw new RuntimeException(ex);
} // fim try
return alunos;
}// fim lista
public Aluno busca(int id) {
String sql = "select * from gafanhotos where id = ?";
Aluno aluno = null;
try (PreparedStatement stmt = connection.prepareStatement(sql)) {
stmt.setLong(1, id);
ResultSet rs = stmt.executeQuery();
if (rs.next()) {
aluno = new Aluno();
aluno.setId(rs.getInt("id"));
aluno.setNome(rs.getString("nome"));
aluno.setProfissao(rs.getString("profissao"));
Calendar data = Calendar.getInstance();
data.setTime(rs.getDate("nascimento"));
aluno.setNascimento(data);
aluno.setSexo(rs.getString("sexo").charAt(0));
aluno.setPeso(rs.getDouble("peso"));
aluno.setAltura(rs.getDouble("altura"));
aluno.setCursoPreferido(rs.getInt("cursoPreferido"));
} // fim if
} catch (SQLException ex) {
throw new RuntimeException(ex);
} // fim try
return aluno;
}// fim busca
public void altera(Aluno aluno) {
String sql = "update gafanhotos set nome = ?, profissao = ?,"
+ " nascimento = ?, sexo = ?, peso = ?, altura = ?, nacionalidade = ?, "
+ "cursopreferido = ? where id = ?";
try (PreparedStatement stmt = connection.prepareStatement(sql)) {
stmt.setString(1, aluno.getNome());
stmt.setString(2, aluno.getProfissao());
stmt.setDate(3, new Date(aluno.getNascimento().getTimeInMillis()));
stmt.setString(4, String.valueOf(aluno.getSexo()));
stmt.setDouble(5, aluno.getPeso());
stmt.setDouble(6, aluno.getAltura());
stmt.setInt(7, aluno.getCursoPreferido());
stmt.setInt(8, aluno.getId());
stmt.executeUpdate();
} catch (SQLException ex) {
throw new RuntimeException(ex);
} // fim try
}// fim altera
public void remove(Aluno aluno) {
String sql = "delete from gafanhotos where id = ?";
try (PreparedStatement stmt = connection.prepareStatement(sql)) {
stmt.setLong(1, aluno.getId());
stmt.executeUpdate();
} catch (SQLException ex) {
throw new RuntimeException(ex);
} // fim try
} // fim remove
}
Porém na página jsp estou com dúvida e o erro pode ser proveniente dele:
<%@ page language=“java” contentType=“text/html; charset=ISO-8859-1”
pageEncoding=“ISO-8859-1”%>
Cadastro de alunos
Nome: | |
Profissao: | |
Nascimento: | |
Sexo: | |
Peso: | |
Altura: | |
Nascionalidade: | |
Curso Preferido: |
Devido ao servlet, aparece a mensagem de erro 500.
O banco de dados foi criado corretamente, pois estou utilizando o mysql, parâmetro para char, não consegui informar, a mensagem no arquivo servlet aponta para um construtor “string”, não lembro se da mesma preciso colocar um conteúdo para string como no jdbc
Logo depois apareceu outra mensagem de erro 404.
HTTP Status 404 - /escola-web/cadastraAluno
type Status report
message /escola-web/cadastraAluno
description The requested resource is not available.
Apache Tomcat/7.0.47