How to get a parameter from JAVA httpSession and use/set it on a dao class?
I need to use a servlet to validate login/password. That's fine already.

I have a method in a DAO class that returns a resultSet list of values through a prepareStatement.

I'm using a query that brings this filtered result with a where clause (by user's name).

The problem is: how can I get the servlet parameter (name of the user who logged in) and set it  on the prepareStatement ?

The code follows:

    public class DaoPojoJoin extends Dao {

    public List<PojoJoin> listUserDegrees() {
        List<PojoJoin> dg = new ArrayList<PojoJoin>();
        if (openConnection()) {
            try {
                st = cn.prepareStatement("SELECT USER, MATTER, DEGREE FROM DEGREES x "
                        + "right outer join USERS y on x.idUser=y.idUser "
                        + "right outer join MATTER z on idMatter=z.idMatter "
                        + "where x.iduser=?"); // filter result by user's name
               
                // How can I have something like this:
                // st.setString(1,usr.request.getParameter("user"));
                
                // or this:
                // st.setString(1,.getAttribute(user));
                
                rs = st.executeQuery();
                while (rs.next()) {
                    PojoJoin pj = new PojoJoin();
                    rs.getString("USER"); 
                    rs.getString("MATTER");
                    rs.getDouble("DEGREE");
                    pj.setUsuario(rs.getString("USER"));
                    pj.setDisciplina(rs.getString("MATTER"));
                    pj.setNota(rs.getDouble("DEGREE"));
                    nota.add(pj);
                }
            } catch (Exception ex) {
                err = ex.getMessage();
            } finally {
                closeConnection();
            }
        }
        return dg;
    }
}


Thanks in advance.
How to get a parameter from JAVA httpSession and use/set it on a dao class?
===

I need to use a servlet to validate login/password. That's fine already.

I have a method in a DAO class that returns a resultSet list of values through a prepareStatement.

I'm using a query that brings this filtered result with a where clause (by user's name).

The problem is: how can I get the servlet parameter (name of the user who logged in) and set it  on the prepareStatement ?

The code follows:

    public class DaoPojoJoin extends Dao {

    public List<PojoJoin> listUserDegrees() {
        List<PojoJoin> dg = new ArrayList<PojoJoin>();
        if (openConnection()) {
            try {
                st = cn.prepareStatement("SELECT USER, MATTER, DEGREE FROM DEGREES x "
                        + "right outer join USERS y on x.idUser=y.idUser "
                        + "right outer join MATTER z on idMatter=z.idMatter "
                        + "where x.iduser=?"); // filter result by user's name
               
                // How can I have something like this:
                // st.setString(1,usr.request.getParameter("user"));
                
                // or this:
                // st.setString(1,.getAttribute(user));
                
                rs = st.executeQuery();
                while (rs.next()) {
                    PojoJoin pj = new PojoJoin();
                    rs.getString("USER"); 
                    rs.getString("MATTER");
                    rs.getDouble("DEGREE");
                    pj.setUsuario(rs.getString("USER"));
                    pj.setDisciplina(rs.getString("MATTER"));
                    pj.setNota(rs.getDouble("DEGREE"));
                    nota.add(pj);
                }
            } catch (Exception ex) {
                err = ex.getMessage();
            } finally {
                closeConnection();
            }
        }
        return dg;
    }
}


Thanks in advance.