How to separate the DAO layer from the data entered by the user?

Asked

Viewed 44 times

0

I am trying to take this DAO layer and put it in another class to receive the data typed by the user. Someone could give a hand?

That is, this piece of code would have to receive the data in another class, the data of the Dadosusuario class.

SocioDAO dao = new SocioDAO();
try {
    dao.salvarSocio(cadastrarUser);
    System.out.println("USUÁRIO CADASTRADO COM SUCESSO.");
} catch (SQLException e) {
    System.out.println("ERRO AO CADASTRAR USUÁRIO.");
    //e.printStackTrace();
}

public class DadosUsuario {

    static Scanner scan = new Scanner(System.in);

    public void cadastrarUsuario() throws NomeUsuarioNaoInformado{
        Socio cadastrarUser = new Socio();

        System.out.println("Informe um nome: ");
        cadastrarUser.setNome(scan.nextLine());

        System.out.println("Informe um telefone: ");
        cadastrarUser.setTelefone(scan.nextInt());

        System.out.println("Informe o DDD: ");
        cadastrarUser.setDdd(scan.nextInt());

        System.out.println("Informe o email: ");
        cadastrarUser.setEmail(scan.next());

        System.out.println("Informe o cpf: ");
        cadastrarUser.setCpf(scan.next());

        SocioDAO dao = new SocioDAO();
        try {
            dao.salvarSocio(cadastrarUser);
            System.out.println("USUÁRIO CADASTRADO COM SUCESSO.");
        } catch (SQLException e) {
            System.out.println("ERRO AO CADASTRAR USUÁRIO.");
            //e.printStackTrace();
        }

    }
}
  • To separate what you say would be... MVC?

  • Yeah... that’s right... only this fuck to do it...

  • An easy way to do this kind of division is to use a framework that will solve much of the architecture. The Demoiselle framework even provides a tool for generating a good part of CRUD: http://demoiselle.sourceforge.net/docs/tools/nimble/1.2.0/html/

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.