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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:15:55+00:00 2026-06-08T17:15:55+00:00

I have a basic question. I have this ArrayList: @Named(AccountProfileController) @ViewScoped public class AccountProfile

  • 0

I have a basic question. I have this ArrayList:

@Named("AccountProfileController")
@ViewScoped
public class AccountProfile implements Serializable
{

    @Resource(name = "jdbc/Oracle")
    private DataSource ds;
    private int id;

    // Constructor
    public AccountProfile()
    {
        // get the ID value 
        try
        {
            this.id = Integer.parseInt((String) FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("id"));
        }
        catch (Exception e)
        {
            this.id = 0;
        }
    }
    // Create List to store user data
    public ArrayList<userdata> dataList = new ArrayList<>();

    public class userdata
    {

        int userid;
        int groupid;
        String specialnumber;
        String username;
        String passwd;
        Date datetochangepasswd;
        String address;
        String stateregion;
        String country;
        String userstatus;
        String telephone;
        Date dateuseradded;
        Date userexpiredate;
        Date dateuserlocked;
        String city;
        String email;
        String description;

        public userdata(int userid, int groupid, String specialnumber, String username, String passwd, Date datetochangepasswd,
                String address, String stateregion, String country, String userstatus, String telephone, Date dateuseradded,
                Date userexpiredate, Date dateuserlocked, String city, String email, String description)
        {

            this.userid = userid;
            this.groupid = groupid;
            this.specialnumber = specialnumber;
            this.username = username;
            this.passwd = passwd;
            this.datetochangepasswd = datetochangepasswd;
            this.address = address;
            this.stateregion = stateregion;
            this.country = country;
            this.userstatus = userstatus;
            this.telephone = telephone;
            this.dateuseradded = dateuseradded;
            this.userexpiredate = userexpiredate;
            this.dateuserlocked = dateuserlocked;
            this.city = city;
            this.email = email;
            this.description = description;
        }

        public String getAddress()
        {
            return address;
        }

        public void setAddress(String address)
        {
            this.address = address;
        }

        public String getCity()
        {
            return city;
        }

        public void setCity(String city)
        {
            this.city = city;
        }

        public String getCountry()
        {
            return country;
        }

        public void setCountry(String country)
        {
            this.country = country;
        }

        public Date getDatetochangepasswd()
        {
            return datetochangepasswd;
        }

        public void setDatetochangepasswd(Date datetochangepasswd)
        {
            this.datetochangepasswd = datetochangepasswd;
        }

        public Date getDateuseradded()
        {
            return dateuseradded;
        }

        public void setDateuseradded(Date dateuseradded)
        {
            this.dateuseradded = dateuseradded;
        }

        public Date getDateuserlocked()
        {
            return dateuserlocked;
        }

        public void setDateuserlocked(Date dateuserlocked)
        {
            this.dateuserlocked = dateuserlocked;
        }

        public String getDescription()
        {
            return description;
        }

        public void setDescription(String description)
        {
            this.description = description;
        }

        public String getEmail()
        {
            return email;
        }

        public void setEmail(String email)
        {
            this.email = email;
        }

        public int getGroupid()
        {
            return groupid;
        }

        public void setGroupid(int groupid)
        {
            this.groupid = groupid;
        }

        public String getPasswd()
        {
            return passwd;
        }

        public void setPasswd(String passwd)
        {
            this.passwd = passwd;
        }

        public String getSpecialnumber()
        {
            return specialnumber;
        }

        public void setSpecialnumber(String specialnumber)
        {
            this.specialnumber = specialnumber;
        }

        public String getStateregion()
        {
            return stateregion;
        }

        public void setStateregion(String stateregion)
        {
            this.stateregion = stateregion;
        }

        public String getTelephone()
        {
            return telephone;
        }

        public void setTelephone(String telephone)
        {
            this.telephone = telephone;
        }

        public Date getUserexpiredate()
        {
            return userexpiredate;
        }

        public void setUserexpiredate(Date userexpiredate)
        {
            this.userexpiredate = userexpiredate;
        }

        public int getUserid()
        {
            return userid;
        }

        public void setUserid(int userid)
        {
            this.userid = userid;
        }

        public String getUsername()
        {
            return username;
        }

        public void setUsername(String username)
        {
            this.username = username;
        }

        public String getUserstatus()
        {
            return userstatus;
        }

        public void setUserstatus(String userstatus)
        {
            this.userstatus = userstatus;
        }
    }

    // Getter for the data list
    public ArrayList<userdata> getuserdata()
    {

        return dataList;
    }

    @PostConstruct
    public void initData() throws SQLException
    {
        //     settingsMap = new HashMap<String, String>();

        if (ds == null)
        {
            throw new SQLException("Can't get data source");
        }
        // Initialize a connection to Oracle
        Connection conn = ds.getConnection();

        if (conn == null)
        {
            throw new SQLException("Can't get database connection");
        }
        // With SQL statement get all settings and values
        PreparedStatement ps = conn.prepareStatement("SELECT * from USERS where USERID = ?");
        ps.setInt(1, id);
        try
        {
            //get data from database        
            ResultSet result = ps.executeQuery();
            while (result.next())
            {
                // Put the the data from Oracle into Array List

                dataList.add(new userdata(result.getInt("USERID"),
                        result.getInt("GROUPID"),
                        result.getString("SPECIALNUMBER"),
                        result.getString("USERNAME"),
                        result.getString("PASSWD"),
                        toDate(result.getString("DATETOCHANGEPASSWD")),
                        result.getString("ADDRESS"),
                        result.getString("STATEREGION"),
                        result.getString("COUNTRY"),
                        result.getString("USERSTATUS"),
                        result.getString("TELEPHONE"),
                        toDate(result.getString("DATEUSERADDED")),
                        toDate(result.getString("USEREXPIREDATE")),
                        toDate(result.getString("DATEUSERLOCKED")),
                        result.getString("CITY"),
                        result.getString("EMAIL"),
                        result.getString("DESCRIPTION")));

            }
        }
        finally
        {
            ps.close();
            conn.close();
        }
    }
    // Call Crypto library for password convert into SHA hash
    @Inject
    @OSGiService(dynamic = true, waitTimeout = 5)
    transient CryptoSHA SHA;

    // Convert Password String into SHA hash
    public String passwdConvert(String password) throws NoSuchAlgorithmException
    {
        return SHA.ShaEncryptHash(password);
    }

    // Insert the data into Oracle
    public void saveData() throws SQLException, java.text.ParseException, NoSuchAlgorithmException
    {

        String SqlStatement = null;

        if (ds == null)
        {
            throw new SQLException();
        }

        Connection conn = ds.getConnection();
        if (conn == null)
        {
            throw new SQLException();
        }

        PreparedStatement ps = null;

        try
        {
            conn.setAutoCommit(false);
            boolean committed = false;
            try
            {           /*
                 * insert into Oracle the default system(Linux) time
                 */


                SqlStatement = "UPDATE USERS "
                        + "SET "
                        + "USERID = ?, "
                        + "GROUPID = ?, "
                        + "SPECIALNUMBER = ?, "
                        + "USERNAME = ?, "
                        + "PASSWD = ?, "
                        + "DATETOCHANGEPASSWD = ?, "
                        + "ADDRESS = ?, "
                        + "STATEREGION = ?, "
                        + "COUNTRY = ?, "
                        + "USERSTATUS = ?, "
                        + "TELEPHONE = ?, "
                        + "DATEUSERADDED = ?, "
                        + "USEREXPIREDATE = ?, "
                        + "DATEUSERLOCKED = ?, "
                        + "CITY = ?, "
                        + "EMAIL = ?, "
                        + "DESCRIPTION = ? "
                        + "WHERE USERID = " + id;

                ps = conn.prepareStatement(SqlStatement);

                ps.setInt(1, dataList.get(userid));
                ps.setInt(2, dataList.get(groupid));
                ps.setString(3, dataList.get(specialnumber));
                ps.setString(4, dataList.get(username));
                ps.setString(5, passwdConvert(dataList.get(passwd)));
                ps.setDate(6, toDate(dataList.get(datetochangepasswd)));
                ps.setString(7, dataList.get(address));
                ps.setString(8, dataList.get(stateregion));
                ps.setString(9, dataList.get(country));
                ps.setString(10, dataList.get(userstatus));
                ps.setString(11, dataList.get(telephone));
                ps.setDate(12, toDate(dataList.get(dateuseradded)));
                ps.setDate(13, toDate(dataList.get(userexpiredate)));
                ps.setDate(14, toDate(dataList.get(dateuserlocked)));
                ps.setString(15, dataList.get(city));
                ps.setString(16, dataList.get(email));
                ps.setString(17, dataList.get(description));


                ps.executeUpdate();

                conn.commit();
                committed = true;
            }
            finally
            {
                if (!committed)
                {
                    conn.rollback();
                }
            }
        }
        finally
        {
            /*
             * Release the resources
             */
            ps.close();
            conn.close();
        }

    }
    //!!!! http://stackoverflow.com/questions/11135675/unparseable-date-30-jun-12
    // Convert the Date format

    public Date toDate(String s)
    {
        Date d = null;
        if (s == null || s.trim().isEmpty())
        {
            return d;
        }

        try
        {
            d = Date.valueOf(s);
        }
        catch (Exception x)
        {
            x.printStackTrace();
        }

        return d;
    }
}

I tried to get the elements using this Java code:

ps.setInt(1, dataList.get(userid));
ps.setInt(2, dataList.get(groupid));
ps.setString(3, dataList.get(specialnumber));
ps.setString(4, dataList.get(username));
ps.setString(5, passwdConvert(dataList.get(passwd)));
ps.setDate(6, toDate(dataList.get(datetochangepasswd)));
ps.setString(7, dataList.get(address));
ps.setString(8, dataList.get(stateregion));
ps.setString(9, dataList.get(country));
ps.setString(10, dataList.get(userstatus));
ps.setString(11, dataList.get(telephone));
ps.setDate(12, toDate(dataList.get(dateuseradded)));
ps.setDate(13, toDate(dataList.get(userexpiredate)));
ps.setDate(14, toDate(dataList.get(dateuserlocked)));
ps.setString(15, dataList.get(city));
ps.setString(16, dataList.get(email));
ps.setString(17, dataList.get(description));

But I get error in Netbeans. Can you tell me what is the proper way to get the elements from the ArrayList?

Best Wishes

  • 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-08T17:15:56+00:00Added an answer on June 8, 2026 at 5:15 pm

    Using for-each loop this is optimize way...

    for(userdata obj : dataList){
    
       System.out.println("User ID :: " + obj.userid);
       System.out.println("Group ID :: " + obj.groupid);
       .
       .
       .
    
    }
    

    Using for loop

    for(int i =0;i<datalist.size();i++){
    
           userdate obj=datalist.get(i);
           System.out.println("User ID :: " + obj.userid);
           System.out.println("Group ID :: " + obj.groupid);
           .
           .
           .
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basic C# syntax question: So I have this class public class BrandQuery<T> : Query<T>
Due to my few concepts of Java, I have a basic question. In this
I have a very basic question. Lets take this snippet: #include <stdio.h> void foo(void)
I realize this is a basic question but I have searched online, been to
This may seem like a basic question. I have a light-weight website and would
This is a very basic question...quite embarassing, but here goes: I have a Stopwatch
I'm new to C++, so this question may be basic: I have two classes
I realize this question is pretty basic, but I'm really stuck. I have a
This is probably a basic html/css question... I have a simple one-button form that
This is a basic question. I have the basic SL4/RIA project set up and

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.