title: store a database record to a list
body: <p>How can I put database record into a ArrayList? I want to view it in a jsp files. But, the value of all object in ArrayList is same as the last record in database I selected.</p>
  
  <p>I have these code in my project:</p>
  
  <p><strong>IPBean.java</strong></p>
  
  <pre><code>public class IPBean {
      private String ip;
      private String userName;
      private String password;
      private int maxRetry;    
  
      public String getIp() {
          return ip;
      }    
      protected void setIp(String ip) {
          this.ip = ip;
      }    
      public String getUserName() {
          return userName;
      }    
      protected void setUserName(String userName) {
          this.userName = userName;
      }    
      public String getPassword() {
          return password;
      }    
      protected void setPassword(String password) {
          this.password = password;
      }    
      public int getMaxRetry() {
          return maxRetry;
      }    
      protected void setMaxRetry(int maxRetry) {
          this.maxRetry = maxRetry;
      }    
  }
  </code></pre>
  
  <p><strong>IPBeanMapper.java</strong></p>
  
  <pre><code>import java.sql.*;
  import java.util.ArrayList;
  
  public class IPBeanMapper {
      public ArrayList&lt;IPBean&gt; getIPList() throws SQLException, ClassNotFoundException {
          ArrayList&lt;IPBean&gt; ipList = new ArrayList&lt;IPBean&gt;();
          Connection conn = null;
          conn = ConnectionTools.getConnection();
          String SQL = "SELECT * FROM LIST_IPM";
          Statement statement = conn.createStatement();
          ResultSet rs = statement.executeQuery(SQL);
          IPBean ipBean = new IPBean();
  
          while (rs.next()){
  
              ipBean.setIp(rs.getString("IP"));
              ipBean.setMaxRetry(rs.getInt("NUM_OF_RETRY"));
              ipBean.setPassword(rs.getString("PASSWORD"));
              ipBean.setUserName(rs.getString("USERNAME"));
  
              ipList.add(ipBean);
  
          }
          ConnectionTools.attemptClose(rs);
          ConnectionTools.attemptClose(statement);
          ConnectionTools.attemptClose(conn);
          System.out.print(ipList.size());
          return ipList;
      }
  }
  </code></pre>
  
  <p><strong>View.jsp</strong>    </p>
  
  <pre><code>&lt;%@ page contentType="text/html;charset=UTF-8" language="java" import="DSIP.*" import="java.util.ArrayList" %&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
      &lt;title&gt;DSIP.Insert&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;jsp:useBean id="ipList" scope="application" class="IPBeanMapper"/&gt;
  &lt;jsp:useBean id="bean" scope="application" class="IPBean"/&gt;
  &lt;form name="form1" method="post" action="viewServlet"&gt;
      &lt;table width="" border=""&gt;
          &lt;tr bgcolor="#0099FF"&gt;
              &lt;td width="90"&gt;&lt;div align="center"&gt;ip&lt;/div&gt;&lt;/td&gt;
              &lt;td width="90"&gt;&lt;div align="center"&gt;username&lt;/div&gt;&lt;/td&gt;
              &lt;td width="90"&gt;&lt;div align="center"&gt;password&lt;/div&gt;&lt;/td&gt;
              &lt;td width="90"&gt;&lt;div align="center"&gt;maxRetry&lt;/div&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;%
              ArrayList&lt;IPBean&gt; list;
              list = ipList.getIPList();
              for (int i = 0; i &lt; list.size(); i++){
                  bean = list.get(i);
          %&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;input name="ip"        type="text" size="15" value="&lt;%=list.getIp()%&gt;"&gt;&lt;/td&gt;
              &lt;td&gt;&lt;input name="userName"  type="text" size="15" value="&lt;%=bean.getUserName()%&gt;"&gt;&lt;/td&gt;
              &lt;td&gt;&lt;input name="password"  type="text" size="15" value="&lt;%=bean.getPassword()%&gt;"&gt;&lt;/td&gt;
              &lt;td&gt;&lt;input name="maxRetry"  type="text" size="15" value="&lt;%=bean.getMaxRetry()%&gt;"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;%
              }
          %&gt;
      &lt;/table&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and the result in my browser shows that the first and second record is indentic when in fact not the same. So, please somebody help me to show the real records from database.</p>
  
  <p>to see my result: <a href="http://i.stack.imgur.com/2lIM9.png" rel="nofollow">http://i.stack.imgur.com/2lIM9.png</a></p>
  
  <p>Thank you very much for helping me.</p>
  
  <p>Best Regards,</p>
  
  <p>Faizal Rizky</p>