Oi pessoal, queria uma ajuda de vocês… Fiz um programa que cadastra veiculo e seu responsavel, onde seus dados principais(cpf e placa) vão para uma tabela chamada historico. Quando eu peço pra listar, não aparece nada!
Nem erro tem… Podem me ajudar?
Abaixo estão os códigos!:
[size=18]ClasseDAO: [/size]
[code]package pacote;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class ClasseDAO {
private Connection connection;
public ClasseDAO(){
this.connection = new ConnectionFactory().getConnection();
}
public void adicionaResponsavel(Responsavel responsavel) {
String sql = "insert into responsavel"
+ "(cpf, endereco, municipio, nome, num_carteira_motorista,uf)"
+ " values (?, ?, ?, ?, ?, ?)";
try {
PreparedStatement stmt;
stmt = connection.prepareStatement(sql);
stmt.setString(1, responsavel.getCpf());
stmt.setString(4, responsavel.getNome());
stmt.setString(2, responsavel.getEndereco());
stmt.setString(6, responsavel.getUf());
stmt.setString(3, responsavel.getMunicipio());
stmt.setString(5, responsavel.getNum_carteira_motorista());
stmt.execute();
stmt.close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
public void adicionaVeiculo(Veiculo veiculo) {
String sql = "insert into veiculo"
+ "(ano, municipio, placa, responsavel,uf)"
+ " values (?, ?, ?, ?, ?)";
try {
PreparedStatement stmt;
stmt = connection.prepareStatement(sql);
stmt.setString(3, veiculo.getPlaca());
stmt.setString(1, veiculo.getAno());
stmt.setString(5, veiculo.getUf());
stmt.setString(2, veiculo.getMunicipio());
stmt.setString(4, veiculo.getResponsavel());
stmt.execute();
stmt.close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
public void adicionaHistorico(Historico historico) {
String sql = "insert into historico"
+ "(responsavel, placa)" + " values (?, ?)";
try {
PreparedStatement stmt;
stmt = connection.prepareStatement(sql);
stmt.setString(2, historico.getPlaca());
stmt.setString(1, historico.getResponsavel());
stmt.execute();
stmt.close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
public List<Historico> getLista() {
try{
List<Historico> historicos = new ArrayList<Historico>();
Connection con = new ConnectionFactory().getConnection();
PreparedStatement stmt;
stmt = con.prepareStatement("select placa from historico" + " where responsavel=?");
stmt.setString(1,"responsavel");
ResultSet rs = stmt.executeQuery();
while(rs.next()) {
Historico historico = new Historico();
historico.setPlaca(rs.getString("placa"));
historicos.add(historico);
}
rs.close();
stmt.close();
return historicos;
}catch (SQLException e) {
throw new RuntimeException(e);
}
}
}[/code]
[size=18]Pesquisa(em html): [/size]
[code]
PesquisaPesquise seu veiculo!
Digite seu CPF:
[/code][size=18]listagem(em jsp): [/size]
[code]<%@page contentType=“text/html” pageEncoding=“UTF-8”%>
<%@ taglib uri=“http://java.sun.com/jsp/jstl/core” prefix=“c” %>
<%@ taglib uri=“http://java.sun.com/jsp/jstl/fmt” prefix=“fmt” %>
<jsp:useBean id=“dao” class=“pacote.ClasseDAO”/>
<c:import url="cabecalho.jsp" />
<!-- Usando o forEach!! -->
<table border="1" align="center">
<c:forEach var="historico" items="${dao.lista}">
<tr>
<td>${historico.placa}</td>
</tr>
</c:forEach>
</table>
<form action="index2.html">
<input type="submit" value="Voltar ao Menu"></p>
</form>
<c:import url="rodape.jsp" />
</body>
[/code]
Obrigada desde já!