Ir para conteúdo
Fórum Script Brasil
  • 0

Ajuda com JAVA


bolomaster

Pergunta

Pessoal, estou pouco familiarizado com JAVA e ontem fazendo um trabalho de desenvolvimento por camadas surgiu o seguinte erro que não consegui resolver

vou postar os .java da camada de negocio e persistencia..

Camada de negocio

Arquivo Clientes.java

package negocio;

public class Clientes
{
    private int id_Cliente;
    private int id_TipoCliente;
    private String nome;
    private String cpf;
    private String rg;
    private String endereco;
    private String cidade;
    private String uf;
    
    public Clientes(int id_TipoCliente, String nome, String cpf, String rg, String endereco, String cidade, String uf)
    {
        this.id_TipoCliente = id_TipoCliente;
        this.nome = nome;
        this.cpf = cpf;
        this.rg = rg;
        this.endereco = endereco;
        this.cidade = cidade;
        this.uf = uf;
        this.id_Cliente =0;
    }
        
    public Clientes (String cpf, String rg)
    {
        this.cpf = cpf;
        this.rg = rg;
        this.id_Cliente = 0;
    }
    
    
    public int getId_TipoCliente() 
    {
        return id_TipoCliente;
    }

    public String getNome() 
    {
        return nome;
    }

    public String getCpf() 
    {
        return cpf;
    }

    public String getRg() 
    {
        return rg;
    }

    public String getEndereco() 
    {
        return endereco;
    }
    
    public String getCidade() 
    {
        return cidade;
    }
    
    public String getUf() 
    {
        return uf;
    }


    public int getId_Cliente() 
    {
        return id_Cliente;
    }

    public void setId_Cliente(int id_Cliente) 
    {
        this.id_Cliente = id_Cliente;
    }
        
}
camada de negocio clientesNegocio.java
package negocio; import java.util.ArrayList; import persistencia.ClientesDAO; public class ClientesNegocio { public int verificarCliente(String cpf, String rg) --- > o erro acontece é nesta linha .. alguém tem alguma soluçao??? { Clientes cliente = new Clientes(cpf, rg); ClientesDAO uDAO = new ClientesDAO(); cliente = uDAO.verificarCliente(cliente); if(cliente.getId_Cliente() == 0 ) { System.out.println("Este Cliente já existe em nosso banco de dados"); } else { System.out.println("Cliente Cadastrado com sucesso em nosso banco de dados"); } } public ArrayList<Clientes> listaClientes() { ClientesDAO uDAO = new ClientesDAO(); return uDAO.verificarCliente("", ""); } public int inserirClientes(int id_TipoCliente,String nome, String cpf, String rg, String endereco, String cidade, String uf ) { if(id_TipoCliente == 0 || nome == "" || cpf == "" || rg == "" || endereco == "" || cidade == "" || uf == "")return 0; ClientesDAO uDAO = new ClientesDAO(); //verifica usuario existente ArrayList<Clientes> ua = uDAO.verificarCliente("CPF = '" + cpf + "'", ""); if(ua.size()>0) return 0; else { //insere usuario Clientes cliente = new Clientes(id_TipoCliente, nome, cpf, rg, endereco, cidade, uf); uDAO.inserirCliente(cliente); return 1; } } }
camada de persistencia arquivo ClientesDAO.java
package persistencia;

import negocio.Clientes;
import java.util.ArrayList;
import java.sql.*;

public class ClientesDAO 
{

    public void inserirCliente (Clientes cliente)
    {
        
        
        try 
        
        
        {
            
            
            Connection con = Banco.getConexao();
            Statement stmt = con.createStatement();
            String query = "INSERT INTO tb_cliente(id_TipoCliente, nome, cpf, rg, endereco, cidade, uf)" +
            " VALUES "+
            "("+ cliente.getId_TipoCliente() + ","+
            "'"+ cliente.getNome() + "',"+
            "'"+ cliente.getCpf() +"'," +
            "'"+ cliente.getRg() + "'," +
            "'"+ cliente.getEndereco() + "',"+
            "'"+ cliente.getCidade() + "',"+
            "'"+ cliente.getUf() + "') ";
            stmt.executeUpdate(query);
            stmt.close();
            con.close();
            
            
            
        } 
        
        
        catch (SQLException e)
        
        
        {
            
            
            System. out.println("Erro = "+e.getMessage());
            
            
        }
        
        
    }
    
    public Clientes consultaClientePK(int id) 
    
    {
        
        
        try
        
        
        {
            
            
            Connection con = Banco.getConexao();
            Clientes cliente = null; 
            Statement stat = con.createStatement();
            ResultSet res = stat.executeQuery("SELECT * FROM tb_cliente where id_Cliente = "+id);
            if(res.next()) 
                
                
            {
                
                
                cliente = new Clientes(res.getInt("id_TipoCliente"), res.getString("nome"), res.getString("cpf"), res.getString("rg"), res.getString("endereco"), res.getString("cidade"),res.getString("uf"));
                cliente.setId_Cliente(id);
                
                
            }
            
            
        return cliente;
        
        
        } 
        
        
        catch(SQLException e) 
        
        
        {
            
            
            System.out.println("Erro = "+e.getMessage());
            return null;
            
            
        } 
        
        
    }
    
    public Clientes consultaTodosClientes() 
    {
        
        try
        
        {
            
            
            Connection con = Banco.getConexao();
            Clientes cliente = null; 
            Statement stat = con.createStatement();
            ResultSet res = stat.executeQuery("SELECT * FROM tb_cliente");
            if(res.next()) 
                
                
            {
                
                
                cliente = new Clientes(res.getInt("id_TipoCliente"), res.getString("nome"), res.getString("cpf"), res.getString("rg"), res.getString("endereco"), res.getString("cidade"),res.getString("uf"));
        
            
            }
            
            
        return cliente;
        
        
        } 
        
        
        catch(SQLException e) 
        
        
        {
            
            
            System.out.println("Erro = "+e.getMessage());
            return null;
            
            
        } 
        
    }
    

    public Clientes verificarCliente(Clientes cliente)
    {
        try
        {
            cliente.setId_Cliente(0);
            Connection con = Banco.getConexao();
            Statement stat = con.createStatement();
            ResultSet res = stat.executeQuery("SELECT * FROM tb_clientes where cpf = '"+cliente.getCpf() + "',and rg='"+cliente.getRg() + "'");
            if(res.next()) 
            {
                cliente = new Clientes(res.getInt("id_TipoCliente"), res.getString("nome"), res.getString("cpf"), res.getString("rg"), res.getString("endereco"), res.getString("cidade"), res.getString("uf"));
                cliente.setId_Cliente(res.getInt("id_Cliente"));
            }
        return cliente;
        }
        
        catch(SQLException e)
        {
            System.out.println("Erro = "+e.getMessage());
            return null; 
        }
    }
    
    public ArrayList<Clientes> verificarCliente(String filtro, String ordem) 
    {
        ArrayList<Clientes> ua = new ArrayList<Clientes>();
        try
        {
            if(filtro.compareTo("") != 0) filtro = " where " + filtro;
            if(ordem.compareTo("") != 0) ordem = " Order By " + ordem;
            Connection con = Banco.getConexao();
            Statement stat = con.createStatement();
            ResultSet res = stat.executeQuery("SELECT * FROM tb_clientes " + filtro + " " + ordem);
            while(res.next()) 
            {
                Clientes cliente;
                cliente = new Clientes(res.getInt("id_TipoCliente"), res.getString("nome"), res.getString("cpf"), res.getString("rg"), res.getString("endereco"),res.getString("cidade"), res.getString("uf"));
                cliente.setId_Cliente(res.getInt("id_Cliente"));
                ua.add(cliente);
            }
        return ua;
        } 
        catch(SQLException e) 
        {
            System.out.println("Erro = "+e.getMessage());
            return null;
        }
        
    }

    
}

o erro está onde eu marquei de vermelho e dá a seguinte msg :

This method must return a result of type int

até o momento eu entendi que o metodo não pode retornar um tipo inteiro, mas tenho outro conjunto de classes para usuarios e está funcionando desta mesma forma... alguém tem alguma sugestão ?

Agradeço a ajuda de todos...

Editado por bolomaster
Link para o comentário
Compartilhar em outros sites

4 respostass a esta questão

Posts Recomendados

  • 0

você criou seu metodo informando q ele iria devolver um resultado do tipo int.

mas no final do metodo você não esta devolvendo nada,

apenas dando um system.out.

ou você termina o metodo com um return 0 (ou outro valor inteiro).

ou altera a assinatura do metodo de int para void.

sucesso ai.

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152k
    • Posts
      651,7k
×
×
  • Criar Novo...