Estou recebendo um erro ao realizar a seguinte consulta:
public class JDBCConsultar {
public Box consultar(Box box) {
Connection consultar = PostgreSQL.getConnection();
try{
String sql = "Select * from box,cliente,endereco where id_box = ?";
PreparedStatement stmt = consultar.prepareStatement(sql);
stmt.setInt(1, box.getId());
ResultSet rs = stmt.executeQuery();
if(rs.next()){
Box box1 = new Box();
box1.setId(rs.getInt("id_box"));
box1.setNumero(rs.getInt("numero"));
box1.setVago(rs.getBoolean("vago"));
box1.getCliente().setId(rs.getInt("id_cliente"));// O erro ocorre nessa linha, "ERRO AO CONSULTAR BOX = NULL"
box1.getCliente().setNome(rs.getString("nome"));
box1.getCliente().setCpf(rs.getLong("cpf"));
box1.getCliente().getEndereco().setId(rs.getInt("id_endereco"));
box1.getCliente().getEndereco().setNumero(rs.getInt("numero"));
box1.getCliente().getEndereco().setRua(rs.getString("rua"));
box1.getCliente().getEndereco().setComplemento(rs.getString("complemento"));
return box1;
}
}catch(Exception e){
JOptionPane.showMessageDialog(null, "erro ao Consultar Box = " + e.getMessage());
}
finally {
try {
consultar.close();
} catch (SQLException ex) {
Logger.getLogger(JDBCCriarTabela.class.getName()).log(Level.SEVERE, null, ex);
}
}
return null;
}
}
Oque pode estar acontecendo?
Obrigado