Como busar pelo id no meu banco?

19 respostas
M

amigos, por favor, estou quebrando a cabeça para fazer uma busca em meu banco pelo id, vi aqui mesmo no forum, varias maneiras de exemplos, mas ainda assim não consegui assimilar com a maneira que esta no meu projeto.
no meu banco, tenho o campo id, no meu form, tenho uma caixa de texto onde insiro o id e faço a pesquisa, o que nao estou conseguindo fazer é pasar isto para o código. vou postar abaixo a parte do DAO, onde faço a pesquisa.

o trecho da minha classe customerDAO:

public Customer buscaPorID(int id) throws SQLException {


        String sql = "select * from clientes where id = ?";
        PreparedStatement pstmt = null;
        pstmt = conexao.prepareStatement(sql);
        this.pstmt.setInt(1, id);

        rs = pstmt.executeQuery();

        Customer customer = null;

        while (rs.next()) {

            customer.setId(rs.getString(id));
            customer.setNome(rs.getString(2));
            customer.setCpf(rs.getString(3));
            customer.setEndereco(rs.getString(4));
            customer.setTelefone(rs.getString(5));
            customer.setEstado(rs.getString(6));
            customer.setCidade(rs.getString(7));

            break;
        }
        rs.close();
        pstmt.close();
        fechaConexao(this.pstmt);
        return customer;

    }

e tenho uma classe CustomerActionListener, onde coloquei os eventos do botões, na parte onde peço para busar pelo ID, dentro do netbeans no trecho do codigo, ele esta
acusando este erro : void’ type not allowed here . e não to conseguindo ver o que estou errando.

public void actionPerformed(ActionEvent event) {

        // identificar o evento executado e chamar o comando adequado.
        
        } else if (event.getActionCommand().equals("Procurar")) {

            mappingCustomerToForm(service.buscaPorID(Integer.parseInt(form.getTextID().getText())));
     } else {
        }

e o trecho da minha classe service, onde busco no dao o método buscarPorID

public void buscaPorID(int id) {
        try {
            dao.buscaPorID(id);
        } catch (Exception ex) {
            Logger.getLogger(CustomerService.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

19 Respostas

P
oi Podes fazer assim:
PreparedStatement pstmt = conexao.prepareStatement("select * from clientes where id = ?");  
        pstmt.setInt(1, id);  
        rs = pstmt.executeQuery();
...   
  
        while (rs.next()) {  
  Customer customer = new Customer(); 
            customer.setId(rs.getInt("id"));  
            customer.setNome(rs.getString("nome da coluna"));  
            ...  
        }

Ai sim é só chamar o método na classe Service
Espero q te ajude =D

M

ola paty… obrigado pelo ajuda… mas não deu certo… na minha classe CustomerActionListener, continua acusando o erro como descrevi acima,
void type not allowed here…

M

ola paty… obrigado pelo ajuda… mas não deu certo… na minha classe CustomerActionListener, continua acusando o erro como descrevi acima,
void type not allowed here…

Guilherme_Gomes

O seu buscarPorId() no servico não tem retorno (void). E vc está passando como parametro dentro de mappingCustomerToForm(). Por isso o erro.

P

o erro aponta para qual linha?
=D

P

Bah pior o Guilherme tem razão tu vai ter q fazer teu metodo buscaPorID da classe service retornar um id para ti poder usar ele na classe CustomerActionListener sem dar erro.
Tenta algo mais ou menos assim:

public int buscaPorID(int id) { try { int idX=0; idX=dao.buscaPorID(id); return idX; } catch (Exception ex) { Logger.getLogger(CustomerService.class.getName()).log(Level.SEVERE, null, ex); } }

M

este é o erro, no proprio codigo no netbeans :
method setId in class br.com.customermanager.model.entity.Customer cannot be applied to given types
required: java.lang.String
found: int

olha a alteracao que fiz no codigo, conforme sua sugestao:

public Customer buscaPorID(int id) throws SQLException {

        Customer customer = null;
        String sql = "select * from clientes where id = ?";
        PreparedStatement pstmt = null;
        pstmt = conexao.prepareStatement(sql);
        this.pstmt.setInt(1, id);
        rs = pstmt.executeQuery();

        while (rs.next()) {

            customer.setId(rs.getInt("id"));
            customer.setNome(rs.getString(2));
P

tah tipo teu id é do tipo String ou int?
coloca como tu tinha feito antes então customer.setId(rs.getString(id)); =P
e tu trocou o método na classe service o retorno dele tem q ser int e não void se não não tem como usar o valor dele em outra classe,tipo sem ter que criar uma variavel e tal =/

M

não deu… agora ele alterei conforme vc passou… ele ta acusando que precisa de um int, e foi encontrado Customer
incompatible types
required: int
found: br.com.customermanager.model.entity.Customer

public int buscaPorID(int id) {
        try { int idX = 0;
            idX = dao.buscaPorID(id);
        return idX;
        } catch (Exception ex) {
            Logger.getLogger(CustomerService.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
M

e meu campo id ta como int

P

Tah vamos por partes quando tu faz mappingCustomerToForm(service.buscaPorID(Integer.parseInt(form.getTextID().getText()))); aquele mappingCustomerToForm é para um objeto do tipo Customer ou int?
Se for do tipo Customer tu altera o retorno para Customer e não int,tipo aquele teu método buscaPorId da classe service tu quer buscar um customer através do id q tu recebe por parametro?
o teu método buscaPorId da classe dao retorna algo?

M

vou postar minha classe dao , o método buscarPorID :

public Customer buscaPorID(int id) throws SQLException {

        Customer customer = null;
        String sql = "select * from clientes where id = ?";
        PreparedStatement pstmt = null;
        pstmt = conexao.prepareStatement(sql);
        this.pstmt.setInt(1, id);

        rs = pstmt.executeQuery();
        while (rs.next()) {

            customer.setId(rs.getString(1));
            customer.setNome(rs.getString(2));
            customer.setCpf(rs.getString(3));
            customer.setEndereco(rs.getString(4));
            customer.setTelefone(rs.getString(5));
            customer.setEstado(rs.getString(6));
            customer.setCidade(rs.getString(7));

            break;
        }
        rs.close();
        pstmt.close();
        fechaConexao(this.pstmt);
        return customer;

    }

na customerservice, ficou desta forma, mas esta dando erro missing return statement.

lic int buscaPorID(int id) {
        try {
            
            dao.buscaPorID(id);
        } catch (Exception ex) {
            Logger.getLogger(CustomerService.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

e na classe actionListener, esta com este erro:

method buscaPorID in class br.com.customermanager.model.service.CustomerService cannot be applied to given types
required: int
found: java.lang.String

e esta desta forma:

mappingCustomerToForm(service.buscaPorID(form.getTextID().getText()));
Diguinho.Max

O seu meto buscaPorId na classe service esta retornando void … ou seja mesmo que ele encontrar um elemento o proprio nao é retornado para quem está chamando este metodo tente alterar de void para Customer e retorne um customer.

P

Tah o 1º erro :missing return statement.
Está faltando o return no teu método tipo:

public int buscaPorID(int id) { try { dao.buscaPorID(id); return .....;//falta o retorno =P //por isso q perguntei vais retornar um int ou um costumer? } catch (Exception ex) { Logger.getLogger(CustomerService.class.getName()).log(Level.SEVERE, null, ex); } }

2ºerro:
Afinal teu id é string ou int ?=p
Olha só no teu método buscapeloid da classe dao tu retorna um costumer e no da classe service um int?
Acho q teu método da classe service deveria ficar assim:

public Costumer buscaPorID(int id) { try { Costumer costumer=new Costumer(); costumer= dao.buscaPorID(id); return costumer; } catch (Exception ex) { Logger.getLogger(CustomerService.class.getName()).log(Level.SEVERE, null, ex); } }

E na ultima classe :

o método mapping toForm rece o q um int ou costumer por parametro se for um int teu método da classe service vai ter q ficar assim:

public int buscaPorID(int id) { try { Costumer costumer=new Costumer(); costumer= dao.buscaPorID(id); return costumer.getId(); } catch (Exception ex) { Logger.getLogger(CustomerService.class.getName()).log(Level.SEVERE, null, ex); } }

M

amigos… olhem só, me desculpem pela confusao, agora nem eu sei mais o que estou fazendo, to confundindo geral…
meu campo id no banco de dados, esta como integer. e meu DAO esta desta forma:

package br.com.customermanager.model.dao;

import br.com.customermanager.model.entity.Customer;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.LinkedList;
import java.util.List;
import javax.swing.JOptionPane;

/**
 *
 * @author marcelo
 */
public class CustomerDao {

    private final static String CREATE_TABLE = "CREATE TABLE  IF NOT EXISTS  clientes (id int(10) "
            + "NOT NULL AUTO_INCREMENT   PRIMARY KEY, nome VARCHAR(20)"
            + " NOT NULL, cpf varchar(20) NOT NULL, telefone varchar(20) NOT NULL)";
    private final static String DELETE_CLIENTE = "DELETE FROM clientes WHERE cpf = '";
    private final static String GET_CLIENTE_CPF = "SELECT * FROM clientes WHERE cpf = ?";
    ResultSet rs = null;
    Statement stmt = null;
    PreparedStatement pstmt = null;
    private Connection conexao;

    public CustomerDao() throws SQLException {

        this.conexao = Conecta.getConexao();
    }

    public void createTable() throws SQLException, Exception {


        Connection conn = null;

        try {
            conn = Conecta.getConexao();
            stmt = conn.createStatement();
            pstmt.executeUpdate(CREATE_TABLE);
        } catch (SQLException e) {
            e.printStackTrace();
            throw new Exception(
                    "Erro ao criar a tabela de clientes : " + CREATE_TABLE, e);
        } finally {
            fechaConexao(pstmt);
        }
    }

    public void create(Customer customer) throws SQLException {

        //  if (!customer.equals(getClienteByCPF(cliente.getCpf()))) {

        String sql = "insert into clientes (nome, cpf, endereco, telefone, estado, cidade)"
                + " values (?,?,?,?,?,?)";

        PreparedStatement stmt = conexao.prepareStatement(sql);

        String msg = null;

        stmt.setString(1, customer.getNome());
        stmt.setString(2, customer.getCpf());
        stmt.setString(3, customer.getEndereco());
        stmt.setString(4, customer.getTelefone());
        stmt.setString(5, customer.getEstado());
        stmt.setString(6, customer.getCidade());


        fechaConexao(stmt);
        JOptionPane.showMessageDialog(null, "Adicionado ao banco de dados");
    }

    public void alterar(Customer customer) throws SQLException {


        String sql = "update clientes set nome = ?, cpf= ?, endereco = ?, telefone= ? , estado = ?, cidade = ? where id = ? ";

        PreparedStatement stmt = conexao.prepareStatement(sql);


        stmt.setString(1, customer.getNome());
        stmt.setString(2, customer.getCpf());
        stmt.setString(3, customer.getEndereco());
        stmt.setString(4, customer.getTelefone());
        stmt.setString(5, customer.getEstado());
        stmt.setString(6, customer.getCidade());
        stmt.setString(7, customer.getId());
        fechaConexao(stmt);
        JOptionPane.showMessageDialog(null, " Cadastro atualizado !!! ");
    }

    public Customer buscaPorID(int id) throws SQLException {

        Customer customer = null;
        String sql = "select * from clientes where id = ?";
        PreparedStatement pstmt = null;
        pstmt = conexao.prepareStatement(sql);
        this.pstmt.setInt(1, id);

        rs = pstmt.executeQuery();
        while (rs.next()) {

            customer.setId(rs.getInt(1));
            customer.setNome(rs.getString(2));
            customer.setCpf(rs.getString(3));
            customer.setEndereco(rs.getString(4));
            customer.setTelefone(rs.getString(5));
            customer.setEstado(rs.getString(6));
            customer.setCidade(rs.getString(7));

            break;
        }
        rs.close();
        pstmt.close();
        fechaConexao(this.pstmt);
        return customer;

    }

    public void remover(Customer customer) throws SQLException {
        String sql = "delete from clientes WHERE ID=?";
        PreparedStatement stmt = conexao.prepareStatement(sql);
        stmt.setString(1, customer.getId());
        stmt.executeUpdate();
        stmt.close();
        JOptionPane.showMessageDialog(null, "Cadastro removido");
    }

    // pelo cpf
    public Customer getClienteCPF(String cpf) throws Exception {
        Connection conn = null;
        PreparedStatement stmt = null;

        Customer cli = null;
        conn = Conecta.getConexao();
        try {
            stmt = conn.prepareStatement(GET_CLIENTE_CPF);
            stmt.setString(1, cpf);
            rs = stmt.executeQuery();
            while (rs.next()) {
                //	cli = new Customer(rs.getString("nome"));
                // , rs
                //.getString("telefone"), rs.getString("cpf"), rs
                // .getInt("id"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            fechaConexao(stmt);
        }
        return cli;
    }

    public List<Customer> getLista() throws SQLException {
        List<Customer> listaContato = new LinkedList<Customer>();
        String sql = "select * from clientes";
        PreparedStatement psm = conexao.prepareStatement(sql);
        ResultSet rset = psm.executeQuery();

        try {
            while (rset.next()) {
                Customer customer = new Customer();

                customer.setNome(rset.getString(1));
                customer.setCpf(rset.getString(2));
                customer.setEndereco(rset.getString(3));
                customer.setTelefone(rset.getString(4));
                customer.setEstado(rset.getString(5));
                customer.setCidade(rset.getString(6));
                listaContato.add(customer);

            }

        } catch (SQLException e) {
            JOptionPane.showMessageDialog(null, "erro na execucao do select");
        } finally {
            rset.close();
            psm.close();
        }
        return listaContato;
    }

    public void fechaConexao(PreparedStatement stmt) throws SQLException {

        stmt.execute();
        stmt.close();
    }
}

a minha classe actionListener esta desta forma:

package br.com.customermanager.model.dao;

import br.com.customermanager.model.entity.Customer;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.LinkedList;
import java.util.List;
import javax.swing.JOptionPane;

/**
 *
 * @author marcelo
 */
public class CustomerDao {

    private final static String CREATE_TABLE = "CREATE TABLE  IF NOT EXISTS  clientes (id int(10) "
            + "NOT NULL AUTO_INCREMENT   PRIMARY KEY, nome VARCHAR(20)"
            + " NOT NULL, cpf varchar(20) NOT NULL, telefone varchar(20) NOT NULL)";
    private final static String DELETE_CLIENTE = "DELETE FROM clientes WHERE cpf = '";
    private final static String GET_CLIENTE_CPF = "SELECT * FROM clientes WHERE cpf = ?";
    ResultSet rs = null;
    Statement stmt = null;
    PreparedStatement pstmt = null;
    private Connection conexao;

    public CustomerDao() throws SQLException {

        this.conexao = Conecta.getConexao();
    }

    public void createTable() throws SQLException, Exception {


        Connection conn = null;

        try {
            conn = Conecta.getConexao();
            stmt = conn.createStatement();
            pstmt.executeUpdate(CREATE_TABLE);
        } catch (SQLException e) {
            e.printStackTrace();
            throw new Exception(
                    "Erro ao criar a tabela de clientes : " + CREATE_TABLE, e);
        } finally {
            fechaConexao(pstmt);
        }
    }

    public void create(Customer customer) throws SQLException {

        //  if (!customer.equals(getClienteByCPF(cliente.getCpf()))) {

        String sql = "insert into clientes (nome, cpf, endereco, telefone, estado, cidade)"
                + " values (?,?,?,?,?,?)";

        PreparedStatement stmt = conexao.prepareStatement(sql);

        String msg = null;

        stmt.setString(1, customer.getNome());
        stmt.setString(2, customer.getCpf());
        stmt.setString(3, customer.getEndereco());
        stmt.setString(4, customer.getTelefone());
        stmt.setString(5, customer.getEstado());
        stmt.setString(6, customer.getCidade());


        fechaConexao(stmt);
        JOptionPane.showMessageDialog(null, "Adicionado ao banco de dados");
    }

    public void alterar(Customer customer) throws SQLException {


        String sql = "update clientes set nome = ?, cpf= ?, endereco = ?, telefone= ? , estado = ?, cidade = ? where id = ? ";

        PreparedStatement stmt = conexao.prepareStatement(sql);


        stmt.setString(1, customer.getNome());
        stmt.setString(2, customer.getCpf());
        stmt.setString(3, customer.getEndereco());
        stmt.setString(4, customer.getTelefone());
        stmt.setString(5, customer.getEstado());
        stmt.setString(6, customer.getCidade());
        stmt.setString(7, customer.getId());
        fechaConexao(stmt);
        JOptionPane.showMessageDialog(null, " Cadastro atualizado !!! ");
    }

    public Customer buscaPorID(int id) throws SQLException {

        Customer customer = null;
        String sql = "select * from clientes where id = ?";
        PreparedStatement pstmt = null;
        pstmt = conexao.prepareStatement(sql);
        this.pstmt.setInt(1, id);

        rs = pstmt.executeQuery();
        while (rs.next()) {

            customer.setId(rs.getInt(1));
            customer.setNome(rs.getString(2));
            customer.setCpf(rs.getString(3));
            customer.setEndereco(rs.getString(4));
            customer.setTelefone(rs.getString(5));
            customer.setEstado(rs.getString(6));
            customer.setCidade(rs.getString(7));

            break;
        }
        rs.close();
        pstmt.close();
        fechaConexao(this.pstmt);
        return customer;

    }

    public void remover(Customer customer) throws SQLException {
        String sql = "delete from clientes WHERE ID=?";
        PreparedStatement stmt = conexao.prepareStatement(sql);
        stmt.setString(1, customer.getId());
        stmt.executeUpdate();
        stmt.close();
        JOptionPane.showMessageDialog(null, "Cadastro removido");
    }

    // pelo cpf
    public Customer getClienteCPF(String cpf) throws Exception {
        Connection conn = null;
        PreparedStatement stmt = null;

        Customer cli = null;
        conn = Conecta.getConexao();
        try {
            stmt = conn.prepareStatement(GET_CLIENTE_CPF);
            stmt.setString(1, cpf);
            rs = stmt.executeQuery();
            while (rs.next()) {
                //	cli = new Customer(rs.getString("nome"));
                // , rs
                //.getString("telefone"), rs.getString("cpf"), rs
                // .getInt("id"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            fechaConexao(stmt);
        }
        return cli;
    }

    public List<Customer> getLista() throws SQLException {
        List<Customer> listaContato = new LinkedList<Customer>();
        String sql = "select * from clientes";
        PreparedStatement psm = conexao.prepareStatement(sql);
        ResultSet rset = psm.executeQuery();

        try {
            while (rset.next()) {
                Customer customer = new Customer();

                customer.setNome(rset.getString(1));
                customer.setCpf(rset.getString(2));
                customer.setEndereco(rset.getString(3));
                customer.setTelefone(rset.getString(4));
                customer.setEstado(rset.getString(5));
                customer.setCidade(rset.getString(6));
                listaContato.add(customer);

            }

        } catch (SQLException e) {
            JOptionPane.showMessageDialog(null, "erro na execucao do select");
        } finally {
            rset.close();
            psm.close();
        }
        return listaContato;
    }

    public void fechaConexao(PreparedStatement stmt) throws SQLException {

        stmt.execute();
        stmt.close();
    }
}

e minha classe customerService, agora, esta desta forma:

package br.com.customermanager.model.service;

import br.com.customermanager.model.dao.CustomerDao;
import br.com.customermanager.model.entity.Customer;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author aluno
 */
public class CustomerService {

    private CustomerDao dao;

    public CustomerService() {
        try {
            dao = new CustomerDao();
        } catch (SQLException ex) {
            Logger.getLogger(CustomerService.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void create(Customer customer) {
        try {
            dao.create(customer);
        } catch (SQLException ex) {
            Logger.getLogger(CustomerService.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public int buscaPorID(int id) {
        try {
            Customer customer = new Customer();
            customer = dao.buscaPorID(id);
            return customer.getId();
        } catch (Exception ex) {
            Logger.getLogger(CustomerService.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void excluir(Customer customer) {
        try {
            dao.remover(customer);
        } catch (Exception ex) {
            Logger.getLogger(CustomerService.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void exibir(Customer customer) {
        //   System.out.println("Exibir " + customer);
        try {
            dao.getLista();
        } catch (SQLException ex) {
            Logger.getLogger(CustomerService.class.getName()).log(Level.SEVERE, null, ex);

        }

    }

    public void alterar(Customer customer) {
        System.out.println("Alterar " + customer);
        try {
            dao.alterar(customer);
        } catch (SQLException ex) {
            Logger.getLogger(CustomerService.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
}

deste jeito que esta, na customer service, esta apresentando o mesmo erro:

missing return statement

ja mechi tando no codigo, que não sei mais o que ta errado, e o que esta certo… …rsrs…desculpem…

M

coloquei o projeto no sendspace… se quiserem dar uma olha

o link : http://www.sendspace.com/file/ysduqx

M

ops… postei errado…

a classe CustomerActionListener é esta :

package br.com.customermanager.controller.customer;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
// import br.com.customermanager.controller.customer.;
import br.com.customermanager.model.entity.Customer;
import br.com.customermanager.model.service.CustomerService;
import br.com.custommanager.view.controller.CustomerForm;
import java.security.IdentityScope;
import java.sql.SQLException;

/**
 *
 * @author aluno
 */
public class CustomerActionListener implements ActionListener {

    private CustomerForm form;
    private CustomerService service;

    public CustomerActionListener(CustomerForm form) {
        this.form = form;
        service = new CustomerService();

    }

    public void actionPerformed(ActionEvent event) {

        // identificar o evento executado e chamar o comando adequado.

        if (event.getActionCommand().equals("Exibir")) {
            service.exibir(mappingFormToCustomer());
        }

        if (event.getActionCommand().equals("Alterar")) {

            service.alterar(mappingFormToCustomer());

        } else if (event.getActionCommand().equals("Cadastrar")) {

            service.create(mappingFormToCustomer());  // recebe a instancia do form

        } else if (event.getActionCommand().equals("Excluir")) {

            service.excluir(mappingFormToCustomer());

        } else if (event.getActionCommand().equals("Procurar")) {

            mappingCustomerToForm(service.buscaPorID(Integer.parseInt( form.getTextID().getText())));
            


        } else {
        }            // pode saber qual foi acionador através do getactioncomand
        // que é o nome do label

    }
    // mapear o texto do form para o nosso objeto (instancia

    public Customer mappingFormToCustomer() {

        Customer customer = new Customer();

        customer.setNome(form.getTextNome().getText());
        customer.setCpf(form.getTextCpf().getText());
        customer.setEndereco(form.getTextEndereco().getText());
        customer.setTelefone(form.getTextTelefone().getText());
        customer.setEstado(form.getTextEstado().getText());
        customer.setCidade(form.getTextCidade().getText());
        customer.setId(form.getTextID().getText());


        return customer;
    }

    public void mappingCustomerToForm(Customer customer) {

        // popula os textos do db com os do form e add nos dados.
        form.getTextNome().setText(customer.getNome());
        form.getTextCpf().setText(customer.getCpf());
        form.getTextEndereco().setText(customer.getEndereco());
        form.getTextTelefone().setText(customer.getTelefone());
        form.getTextEstado().setText(customer.getEstado());
        form.getTextCidade().setText(customer.getCidade());
        form.getTextID().setText(customer.getId());


    }
}
P
esse erro da para arrumar fazendo o seguinte:
public int buscaPorID(int id) {  
        try {  
            Customer customer = new Customer();  
            customer = dao.buscaPorID(id);  
       
        } catch (Exception ex) {  
            Logger.getLogger(CustomerService.class.getName()).log(Level.SEVERE, null, ex);  
        }  
     return customer.getId();  
    }
P
esse erro da para arrumar fazendo o seguinte:
public int buscaPorID(int id) {  
       Customer customer = new Customer(); 
   try {  
           
            customer = dao.buscaPorID(id);  
       
        } catch (Exception ex) {  
            Logger.getLogger(CustomerService.class.getName()).log(Level.SEVERE, null, ex);  
        }  
     return customer.getId();  
    }
Criado 6 de outubro de 2011
Ultima resposta 6 de out. de 2011
Respostas 19
Participantes 4