0
I’m trying to select the dvds that the partner registered but I’m not getting, I wonder if someone can help me, the result of my code returns like this Result:
1 - null - null - null - null - null - null - 2
And only one result appears, I need him to check the entire bank and show the user only the dvds registered by him, to list all the dvds I got but this one is killing me.
Class Socio
:
public class Socio {
protected Long codigo;
protected String nome;
protected Integer telefone;
protected Integer ddd;
protected String email;
protected String cpf;
// getters e setters
@Override
public String toString() {
String saida = cpf + " - " + nome + " - " + telefone + " - " + ddd
+ " - " + email + " - " + codigo;
return saida;
}
}
Class Dvd
:
package dominio;
import java.util.Scanner;
public class Dvd {
private Long codigo;
protected String titulo;
protected String genero;
protected String descricaoGenero;
protected Double duracao;
protected String sinopse;
protected String idioma;
protected String legenda;
protected Integer anoProducao;
private Socio socio = new Socio();
// getters e setters
@Override
public String toString() {
Socio s = new Socio();
String saida = titulo + " - " + genero + " - " + descricaoGenero
+ " - " + duracao + " - " + sinopse + " - " + idioma + " - "
+ anoProducao + " - " + codigo ;
return saida;
}
}
List method in DvdDao
:
public Dvd listarDvdsPorCodigoSocio(Dvd f) throws SQLException{
StringBuilder sql = new StringBuilder();
sql.append("SELECT codigo, socio_codigo, titulo ");
sql.append("FROM dvd ");
sql.append("WHERE socio_codigo = ? ");
Connection conexao = FabricaDeConexao.conectar();
PreparedStatement comando = conexao.prepareStatement(sql.toString());
comando.setLong(1, f.getSocio().getCodigo());
ResultSet resultado = comando.executeQuery();
Dvd retorno = null;
while(resultado.next()){
retorno = new Dvd();
retorno.setCodigo(resultado.getLong("codigo"));
retorno.setTitulo(resultado.getString("titulo"));
retorno.setTitulo(resultado.getString("socio_codigo"));
}
return retorno;
}
And how I’m wearing it:
public void buscarDvdsPorSocio () throws SQLException{
Dvd f2 = new Dvd();
AdicionarSocioVisao e = new AdicionarSocioVisao();
e.solicitarCodigoUsuario();
f2.setSocio(e);
try {
DvdDAO fdao = new DvdDAO();
Dvd f3 = fdao.listarDvdsPorCodigoSocio(f2);
System.out.println("Resultado 1: "+f3);
} catch (SQLException ex) {
System.out.println("OCORREU UM ERRO..." + ex);
ex.printStackTrace();
}
}
listarDvdsPorCodigoSocio
should return a list ofDvd
as opposed to only oneDvd
, nay?– Bruno César