LostSoldier,
Desculpe-me pela ignorancia e falta de experiência nesse assunto, mas como percebeu ainda estou engatinhando em desenvolvimento. Tentei fazer as modificações mas também não obtive êxito.
Não sei como implementar o método pesquisar, que tipo de retorno ele utiliza, não sei se uso o mesmo para listar os alunos cadastrados.
Ficou assim a minha implementação…
CLASSE Pesquisar no DAO
public Aluno pesquisar(int id) {
try {
String sql = "select nome, datanasc, email, telefone, endereco from alunos where id=?";
PreparedStatement stm = (PreparedStatement) connection.prepareStatement(sql);
ResultSet rs = (ResultSet) stm.executeQuery();
while (rs.next()) {
Aluno aluno = new Aluno();
aluno.setId(rs.getInt("id"));
aluno.setNome(rs.getString("nome"));
Calendar data = Calendar.getInstance();
data.setTime(rs.getDate("datanasc"));
aluno.setDatanasc(data);
aluno.setEmail(rs.getString("email"));
aluno.setTelefone(rs.getString("telefone"));
aluno.setEndereco(rs.getString("endereco"));
}
rs.close();
stm.close();
return null;
} catch (Exception e) {
throw new RuntimeException(e);
}
OBS: NÃO SEI SE ESSE MÉTODO É FEITO DESSA FORMA!!!
SE USO O RETORNO VOID, A CLASSE PaginaAlteraAlunosLogic RECLAMA.
Classe PaginaAlteraAlunosLogic
public class PaginaAlteraAlunosLogic implements Logica{
@Override
public String executa(HttpServletRequest req, HttpServletResponse resp) throws Exception {
int id = Integer.parseInt(req.getParameter("id"));
AlunoDao dao = new AlunoDao();
Aluno aluno = dao.pesquisar(id);
req.setAttribute("alunoSelecionado", aluno);
return "/WEB-INF/jsp/alteraAlunos.jsp";
}
}
QUANDO EXECUTO TUDO, RECEBO O SEGUINTE ERRO…
HTTP Status 500 - A lógica de negócios causou uma exceção
type Exception report
message A lógica de negócios causou uma exceção
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: A lógica de negócios causou uma exceção
br.com.listagens.mvc.servlets.ControllerServlets.service(ControllerServlets.java:36)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.lang.RuntimeException: java.sql.SQLException: No value specified for parameter 1
br.com.listagens.dao.AlunoDao.pesquisar(AlunoDao.java:124)
br.com.listagens.mvc.logica.PaginaAlteraAlunosLogic.executa(PaginaAlteraAlunosLogic.java:17)
br.com.listagens.mvc.servlets.ControllerServlets.service(ControllerServlets.java:30)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.sql.SQLException: No value specified for parameter 1
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:1737)
com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:1685)
com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1396)
br.com.listagens.dao.AlunoDao.pesquisar(AlunoDao.java:98)
br.com.listagens.mvc.logica.PaginaAlteraAlunosLogic.executa(PaginaAlteraAlunosLogic.java:17)
br.com.listagens.mvc.servlets.ControllerServlets.service(ControllerServlets.java:30)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.75 logs.
AGRADEÇO PELA AJUDA MAIS UMA VEZ!