Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6878879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:46:41+00:00 2026-05-27T04:46:41+00:00

So with relation to the previous method. This is my UserDAO, and DaoFactory. The

  • 0

So with relation to the previous method. This is my UserDAO, and DaoFactory. The UserDao holds an instance of the daoFactory.

This is my UserDAO:

public class UsuariousDAO {

    private static final String SQL_LIST_ALL =
            "SELECT DISTINCT * "
            + "FROM usuarios WHERE NOT EXISTS (SELECT * FROM usuarios_grupos WHERE usuarios_grupos.id_grupo = ? AND usuarios_grupos.id_usuario = usuarios.id_usuario)";


    private static final String SQL_INSERT =
            "INSERT INTO usuarios (nome, setor, senha, email, bloquear, admin) VALUES (?, ?, ?, ?, ?, ?)";

    private static final String SQL_UPDATE =
            "UPDATE usuario SET nome = ?, setor = ?, senha = ?, email = ?, bloquear = ?, admin = ? WHERE id_usuario = ?";

    private static final String SQL_DELETE =
            "DELETE FROM usuario WHERE id_usuario = ?";

    private DAOFactory daoFactory;

     UsuariousDAO(DAOFactory daoFactory) {
        this.daoFactory = daoFactory;
    }

     public Usuarious find(Integer id) throws DAOExceptions {
        return find(SQL_LIST_BY_ID_GRUPO, id);
    }

I have the following methods in my USERDAO:

private Usuarious find(String sql, Object... values) throws DAOExceptions {

                                CODE
}

 public List<Usuarious> list() throws DAOExceptions {

                               CODE
}

 public List<Usuarious> list(Grupos groups) throws DAOExceptions {

                                   CODE
    }


 public void create(Usuarious user) throws IllegalArgumentException, DAOExceptions {

                              CODE
}


public void update(Usuarious user) throws DAOExceptions {
                                  CODE
}



public void save(Usuarious user) throws DAOExceptions {
        if (user.getId_usuario() == null) {
            create(user);
        } else {
            update(user);
        }
    }


public void delete(Usuarious user) throws DAOExceptions {

                    CODE
}

   private static Usuarious mapUser(ResultSet rs) throws SQLException {
        Usuarious user = new Usuarious(rs.getInt("id_usuario"), rs.getString("nome"), rs.getString("setor"),
                rs.getString("senha"), rs.getString("email"), rs.getString("bloquear"), rs.getString("admin"));
        return user;
    }

} //end of class

MY DaoFactory class is the following:

     public abstract class DAOFactory  {

        private static final String JNDI_ROOT = "java:comp/env/";

         public static DAOFactory getInstance(String name) throws DAOConfigurationException {
            if (name == null) {
                throw new DAOConfigurationException("Database name is null.");
            }

            String url = "jdbc:mysql://200.230.71.12:3306/social";
            String driverClassName = "com.mysql.jdbc.Driver";
            String password = "1234cinco";
            String username = "cepein";
            DAOFactory instance;

   if (driverClassName != null) {
            try {
                Class.forName(driverClassName);
            } catch (ClassNotFoundException e) {
                throw new DAOConfigurationException(
                    "Driver class '" + driverClassName + "' is missing in classpath.", e);
            }
            instance = new DriverManagerDAOFactory(url, username, password);
        }

        // Else assume URL as DataSource URL and lookup it in the JNDI.
        else {
            DataSource dataSource;
            try {
                dataSource = (DataSource) new InitialContext().lookup(JNDI_ROOT + url);
            } catch (NamingException e) {
                throw new DAOConfigurationException(
                    "DataSource '" + url + "' is missing in JNDI.", e);
            }
            if (username != null) {
                instance = new DataSourceWithLoginDAOFactory(dataSource, username, password);
            } else {
                instance = new DataSourceDAOFactory(dataSource);
            }
        }

        return instance;
    }




  abstract Connection getConnection() throws SQLException;

        // DAO getters --------------------------------------------------------------------------------

        /**
         * Returns the User,Grupos, UserGrupos DAO associated with the current DAOFactory.
         * @return The User,Grupos, UserGrupos DAO associated with the current DAOFactory.
         */


          public UsuariousDAO getUserDAO() {
        return new UsuariousDAO(this);
    }

    public GruposDAO getGruposDAO() {
        return new GruposDAO(this);
    }

    public UsuariousGruposDAO getUsuariousGruposDAO() {
        return new UsuariousGruposDAO(this);
    }

}


class DriverManagerDAOFactory extends DAOFactory {
    private String url;
    private String username;
    private String password;

    DriverManagerDAOFactory(String url, String username, String password) {
        this.url = url;
        this.username = username;
        this.password = password;
    }

    Connection getConnection() throws SQLException {
        return DriverManager.getConnection(url, username, password);
    }
}

/**
 * The DataSource based DAOFactory.
 */
class DataSourceDAOFactory extends DAOFactory {
    private DataSource dataSource;

    DataSourceDAOFactory(DataSource dataSource) {
        this.dataSource = dataSource;
    }

    Connection getConnection() throws SQLException {
        return dataSource.getConnection();
    }
}

/**
 * The DataSource-with-Login based DAOFactory.
 */
class DataSourceWithLoginDAOFactory extends DAOFactory {
    private DataSource dataSource;
    private String username;
    private String password;

    DataSourceWithLoginDAOFactory(DataSource dataSource, String username, String password) {
        this.dataSource = dataSource;
        this.username = username;
        this.password = password;
    }

    Connection getConnection() throws SQLException {
        return dataSource.getConnection(username, password);
    }
}

Here is my list(Grupos grps):

 public List<Usuarious> list(Grupos groups) throws DAOExceptions {
    Connection connection = null;
    PreparedStatement preparedStatement = null;
    ResultSet resultSet = null;
    List<Usuarious> users = new ArrayList<Usuarious>();

    try {
        connection = daoFactory.getConnection();
        preparedStatement = connection.prepareStatement(SQL_LIST_ALL);
        preparedStatement.setInt(1, groups.getId_grupo());
        resultSet = preparedStatement.executeQuery();
        while (resultSet.next()) {
            users.add(mapUser(resultSet));
        }
    } catch (SQLException e) {
        throw new DAOExceptions(e);
    } finally {
        close(connection, preparedStatement, resultSet);
    }

    return users;
}

I call the method in my User managed bean here:

public List<Usuarious> getListOfUsuarios() throws DAOExceptions {
        List<Usuarious> usuariosList = userDAO.list(grps);
        listOfUsuarios = usuariosList;
        return listOfUsuarios;
    }

and in my view, the following:

<p:dataTable var="users" value="#{usuariousGruposBean.listOfUsuarios}"
                                 selection="#{users}" selectionMode="single">
                        <p:column headerText="" style="height:0" rendered ="false">
                            <h:outputText value="#{users.id_usuario}"/>
                        </p:column> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:46:41+00:00Added an answer on May 27, 2026 at 4:46 am

    The variable groups is null when you call this method, so the problem is in the caller and not here.

    NullPointerException on preparedStatement.setInt(1, groups.getId_grupo()); means that either preparedStatement or groups are null (but we now preparedStatement is not).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In relation to this previous question I am trying to create a batch file
This is in relation to a previous question I asked here. Calling replaceAll(\n, <br
This question has a relation with my previous question, What is the real memory
This question is in relation to a previous question I've asked ... see SQL
This is in relation to my previous question: D concurrent writing to buffer Say
In relation to this question on Using OpenGL extensions , what's the purpose of
In relation to this stackoverflow question , how would I go about creating my
In relation to this question ( Efficient hashCode() implementation ) I have one more
This is in relation to this question I am hosting this WCF service in
I have a relation mapping table like this: attributeid bigint productid bigint To clean

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.