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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:22:49+00:00 2026-05-23T04:22:49+00:00

I have a SQL query that returns a number of results (unfortunately, the number

  • 0

I have a SQL query that returns a number of results (unfortunately, the number of results will vary). Currently, I am storing the results into an arrayList like so:

ArrayList allTerms = new ArrayList();


try {

  String selStmt = "SELECT .... ";

  stmt = conn.prepareStatement(selStmt);
  result = stmt.executeQuery();
  Object result_data;

  while (result.next()) {    
      term = (((result_data = result.getObject("internal_code"))==null || result.wasNull())?" ":result_data.toString());
      allTerms.add(term);
      desc = (((result_data = result.getObject("external_representation"))==null || result.wasNull())?" ":result_data.toString());
      allTerms.add(desc);
      sorter = (((result_data = result.getObject("sorter"))==null || result.wasNull())?" ":result_data.toString());
      allTerms.add(sorter);
      sDate = (((result_data = result.getObject("sDate"))==null || result.wasNull())?" ":result_data.toString());
      allTerms.add(sDate);
  }
  System.out.println(allTerms);

Okay, so when I run this, the system prints:

[2011SP, Spring 2011, 1, 11-15-2010, 2011SU, Summer 2011, 1, 01-15-2011, 2011FL, Fall 2011, 1, 04-01-2011, 2010Q2, CE Qtr 2 2010 Dec - Feb, 2, 08-01-2010, 2011Q3, CE Qtr 3 2011 Mar - May, 2, 11-01-2010, 2011Q4, CE Qtr 4 2011 Jun - Aug, 2, 02-01-2011, 2011Q1, CE Qtr 1 2011 Sep-Nov, 2, 05-01-2011]

I dont know if this is the correct way of doing it or not, but it is working so far, so what I want to do now is use my allTerms arrayList to transfer these results to parts of a HTML page. so for ex:

<table class="t1">
  <tr>
    <td><!--Here I would want to show all rows from the allTerms arrayList with a "sorter" of 1--></td>
  </tr>
</table>
<table class="t2">
  <tr>
    <td><!--Here I would want to show all rows from the allTerms arrayList with a "sorter" of 1 and a term of ....SU (where '....' is the year) --></td>
  </tr>
</table>
  • 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-23T04:22:50+00:00Added an answer on May 23, 2026 at 4:22 am

    It’s a lot easier if you just define a short value holder class, like:

    public class Row {  // give it a better name ;)
      public String internalCode;
      public String externalRepresentation;
      public String sorter;
      public String sDate;
    }
    

    then, define a collection that holds these row values:

    List<Row> rows = new ArrayList<Row>();
    

    and add the rows to the list:

    while (result.next()) {    
          Row row = new Row();
          row.internalCode = (((result_data = result.getObject("internal_code"))==null || result.wasNull())?" ":result_data.toString());
          row.externalRepresentation = (((result_data = result.getObject("external_representation"))==null || result.wasNull())?" ":result_data.toString());
          row.sorter = (((result_data = result.getObject("sorter"))==null || result.wasNull())?" ":result_data.toString());
          row.sDate = (((result_data = result.getObject("sDate"))==null || result.wasNull())?" ":result_data.toString());      
    }
    

    Now you can filter on the collection like this:

     for (Row row:rows) {
       if (!row.sorter.equals("1"))
         continue;
    
       // do what has to be done with records where sorter = "1"
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a SQL query that returns results based on a dynamic number
I currently have a SQL query that returns a number of fields. I need
I have a query that currently returns data with the following attributes: A number
I want a SQL like query and have results that start with the input
I have the following Sql Query that returns the type of results that I
I have a SQL query that returns a Datatable: var routesTable = _dbhelper.Select(SELECT [RouteId],[UserId],[SourceName],[CreationTime]
I have an SQL query that returns all companies records ignore the ones with
I have a Microsoft SQL Server 2008 query that returns data from three tables
I have a simple SQL query (using SqlCommand, SqlTransaction) in .NET 2.0 that returns
I'm using Sql-Server, and I have the below query which returns all columns that

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.