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 8160759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:20:58+00:00 2026-06-06T18:20:58+00:00

How can I put database record into a ArrayList? I want to view it

  • 0

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.

I have these code in my project:

IPBean.java

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;
    }    
}

IPBeanMapper.java

import java.sql.*;
import java.util.ArrayList;

public class IPBeanMapper {
    public ArrayList<IPBean> getIPList() throws SQLException, ClassNotFoundException {
        ArrayList<IPBean> ipList = new ArrayList<IPBean>();
        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;
    }
}

View.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" import="DSIP.*" import="java.util.ArrayList" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>DSIP.Insert</title>
</head>

<body>
<jsp:useBean id="ipList" scope="application" class="IPBeanMapper"/>
<jsp:useBean id="bean" scope="application" class="IPBean"/>
<form name="form1" method="post" action="viewServlet">
    <table width="" border="">
        <tr bgcolor="#0099FF">
            <td width="90"><div align="center">ip</div></td>
            <td width="90"><div align="center">username</div></td>
            <td width="90"><div align="center">password</div></td>
            <td width="90"><div align="center">maxRetry</div></td>
        </tr>
        <%
            ArrayList<IPBean> list;
            list = ipList.getIPList();
            for (int i = 0; i < list.size(); i++){
                bean = list.get(i);
        %>
        <tr>
            <td><input name="ip"        type="text" size="15" value="<%=list.getIp()%>"></td>
            <td><input name="userName"  type="text" size="15" value="<%=bean.getUserName()%>"></td>
            <td><input name="password"  type="text" size="15" value="<%=bean.getPassword()%>"></td>
            <td><input name="maxRetry"  type="text" size="15" value="<%=bean.getMaxRetry()%>"></td>
        </tr>
        <%
            }
        %>
    </table>
</form>
</body>
</html>

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.

to see my result: https://i.stack.imgur.com/2lIM9.png

Thank you very much for helping me.

Best Regards,

Faizal Rizky

  • 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-06-06T18:20:59+00:00Added an answer on June 6, 2026 at 6:20 pm

    Change

       IPBean ipBean = new IPBean(); 
    
        while (rs.next()){
    

    to

     while (rs.next()){
    
     IPBean ipBean = new IPBean();
    

    This will create new instance per row, which is required, otherwise it will keep overriding data in a single instance

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

Sidebar

Related Questions

how i can put multiple buttons in scroll view with according to my requirement?
Where are all of the places you can put CSS style information on an
I'm trying to understand when I can put certain objects into a users session
Here is the way I can put float value to the stack(in C#): ILGenerator
MYSQL Database: I have a table of data that I need to put into
I can put python doctests in the bodies of each function, which I sometimes
We can put our file say one.txt in txt folder available in tomcat->webapp folder.
In XAML we can put one long string in the positions property, How do
In C++ you can put a member in a base class and a member
I know I can put escaped HTML tags in string resources. However, looking at

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.