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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:59:56+00:00 2026-05-31T08:59:56+00:00

I have executed a query using JDBC and traversing the resultset I have stored

  • 0

I have executed a query using JDBC and traversing the resultset I have stored all fields in List in java.

List<String> dataList=new ArrayList<String>();
        while(res.next())
        {
            dataList.add(res.getString(1));
            dataList.add(res.getString(2));
            dataList.add(res.getString(3));
            dataList.add(res.getString(4));
            dataList.add(res.getString(5));
            dataList.add(res.getString(6));
            dataList.add(res.getString(7));
        }
        Iterator<String> it= dataList.iterator();

As I have added directly into list so how can I get this 7 fields while traversing the iterator.
Means:

while(it.hasNext())
{
   String f1=it.next();

}

Like wise everytime I want 7 fields at a time
and next 7, next 7……. so on
Using this while loop how can I get those 7 fields (one row in table having 7 field) at a time.

I get little bit confuse here. Please help me.

Thanks

  • 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-31T08:59:57+00:00Added an answer on May 31, 2026 at 8:59 am

    What you want to do is actually create another object that stores all seven of the values.

    Then create a list of these entries so that you can access one row at a time, which is what I think you are asking.

    First create a class for the row.

    private static class Entry {
        String[] row;
    
        public Entry ( ResultSet r ) {
            row = new String [ 7 ];
            for (int i = 1; i <= 7; i++) {
                row[i] = r.getString(i);
            }
        }
    }
    

    Using that, you can then create a list of Entry objects.

    List<Entry> entryList = new ArrayList <Entry> ();
    
    while(res.next())
    {
        entryList.add ( new Entry ( res ) );
    }
    

    Then, you can go ahead and loop through entryList and get any specific entry you would want.

    Of course, if you have specific values, it might be wise to create instance variables of type String for Entry rather than an array of Strings.

    By that I mean you could do this:

    private static class Entry {
        String column1; // rather than name column1 use what the column semantically represents
    
        String column2;
    
        // ...
    
        public Entry ( ResultSet r ) {
            column1 = r.getString(1);
            // ...
        }
    

    This way, you can also calls like r.getInt(i) for certain columns which have an different type other than String.

    Good luck!

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

Sidebar

Related Questions

I have a query in java string. What i need to do is fire
I have a query that might be executed by several users consecutively. I'm scared
I have a query that runs super fast when executed in the sql editor
I have a query which part of a SP which is executed fairly regularly,
I have a complex query that gets executed like this: if ($stmt = $dbi->prepare($pt_query))
I am using jdbc to connect to a postgresql database in a java application
I am running a query on a MySQL database, I am using JDBC and
I'm using Spring 3.0.2 and I have a class called MovieDAO that uses JDBC
I have a java.sql.Clob object which I populate from an Oracle query and then
I have executed the following create statement using SQLWorkbench at my target postgresql database:

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.