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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:51:14+00:00 2026-05-31T03:51:14+00:00

I have a database server communicating with a Java application server using JDBC. I

  • 0

I have a database server communicating with a Java application server using JDBC. I want to store data from the database ResultSet into Java variables.

Here’s my Java class, HRPeople:

public class HRPeople {
    public int elements;
    public String[] FirstName;
    public String[] LastName;
    public String[] Email;
    public int[] Salary;
}

I currently use this class to store data from ResultSet, as follows:

query = "SELECT first_name, last_name, email, salary FROM HR.Employees where rownum < 6";
rset = stmt.executeQuery(query);
while (rset.next()) {
    returnHRdata.FirstName[ii] = rset.getString("first_name");
    returnHRdata.LastName[ii]  = rset.getString("last_name");
    returnHRdata.Email[ii]     = rset.getString("email");
    returnHRdata.Salary[ii]    = rset.getInt("salary");
    ii = ii + 1;
}

The problem with the above scenario is that the primitive arrays require me to know the number of rows in the ResultSet so that I can properly initialize those arrays. So what I want to do is use an ArrayList instead. How would I modify the above scenario to do this?

Here’s my initial attempt (is this close)? Is HRPeople.java file shown above even used in this scenario?

query = "SELECT first_name, last_name, email, salary FROM HR.Employees where rownum < 6";
rset = stmt.executeQuery(query);
List<HRPeople> returnHRdata = new ArrayList<HRPeople>();
while (rset.next()) {
   returnHRdata.FirstName = rset.getString("first_name");
   returnHRdata.LastName  = rset.getString("last_name");
   returnHRdata.Email     = rset.getString("email");
   returnHRdata.Salary    = rset.getInt("salary");
   returnHRdata.add;
}

UPDATE 1:

If I add to the code the following,

return returnHRdata;

I get the following error (any idea why?):

myClass.java:213: incompatible types
found   : java.util.List<HRPerson>
required: java.util.ArrayList<HRPerson>
    return returnHRdata;
           ^
1 error
  • 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-05-31T03:51:16+00:00Added an answer on May 31, 2026 at 3:51 am

    You probably want to first define an HRPerson like this:

    public class HRPerson {
        public String firstName;
        public String lastName;
        public String email;
        public int salary;
    }
    

    Then your main code would look like:

    query = "SELECT first_name, last_name, email, salary FROM HR.Employees where rownum < 6";
    rset = stmt.executeQuery(query);
    List<HRPerson> returnHRdata = new ArrayList<HRPerson>();
    while (rset.next()) {
       HRPerson person = new HRPerson();
       person.firstName = rset.getString("first_name");
       person.lastName  = rset.getString("last_name");
       person.email     = rset.getString("email");
       person.salary    = rset.getInt("salary");
       returnHRdata.add(person);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a game server application (Java) and want to have PHP communicate directly
I have developed a basic Chat application in Java. It consists of a server
I have a strange problem with jdbc connection to an oracle database server. We've
Oracle 10g Application Server, Java 1.5 + JSF (presentation layer) + iBatis (database communication
I have a client-server java application, where communication happens over SSL. Right now I
We have a vehicle tracking system. We are using MySQL as database server. One
We have a database (SQL Server 2005) which we would like to get under
I have a Database (SQL Server) with table named 'ProcessData' and columns named 'Process_Name'
We have SQL Server database setup. We are setting up a replication scenarios where
We have a production SQL Server 2005 database server with the production version of

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.