How to view all users on a database - JDBC Struts

On my database table I have 6 rows of users.

I want to display all the users in the database.

When I run my code I get the value for the 6th row 6 times.

Java

public String allMembers() throws SQLException {
List<String> members = new ArrayList<String>();
    try{ 
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/Web", "root", "root");
        Statement statement = connection.createStatement();
         ResultSet res = statement.executeQuery("select * from Users");
        while (res.next()){
            setUserName(res.getString("userName"));
            userName = userName.trim();
            members.add(userName);
        }
        connection.close();
    }catch (SQLException e) {
        e.printStackTrace();
    }
    return "SUCCESS";
}

JSP

 <td>
     <b>Example of Iterator Tag</b><br/>
     <s:iterator value="members" status="ctr">
     <s:property value="userName"/> 
      </s:iterator>
      <br/><br/>
    </td>

How can I fix this and get it to display all users.

String userName

private String userName;
public String getUserName() {
    return userName;
}

public void setUserName(String userName) {
    this.userName = userName;
}

Answers


In your action class

List<String> members = new ArrayList<String>();

public List<String> getMembers() {
        return members;
    }

    public void setMembers(List<String> members) {
        this.members = members;
    }

In your jsp

<s:iterator value="members" status="memberStatus">
  <tr> 
      <td><s:property/></td>

  </tr>
</s:iterator>

You do

setUserName(res.getString("userName"));

Which does unknown things. But then you continue...

        userName = userName.trim();
        members.add(userName);

Where does userName come from? Where is it set to what?


Need Your Help

ncurses: Is it possible to refresh a window without removing its borders?

c++ ncurses

Since I haven't found anything else online I'm guessing that wborder just "mvprintw"s characters to the appropriate parts of the window instead of actually making a border object or anything deeper...

Logstash not_analyzed

csv logstash kibana elastic-stack

I am a total newby to the ELK stack and probably trying to setup a much to complicated config to start with... :-)