Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-16-2011, 05:11 PM   PM User | #1
d2thalo
New to the CF scene

 
Join Date: Jun 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
d2thalo is an unknown quantity at this point
Help with ArrayList and looping through it

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:
Code:
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:
Code:
[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, and separate them into rows, so I want to split every 4 results into a separate row. (So it would be 2011SP, Spring 2011, 1, 11-15-2010 as one row and so on), next, I would need to transfer these results to parts of a HTML page. so for ex:

Code:
<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>
d2thalo is offline   Reply With Quote
Old 06-17-2011, 12:30 AM   PM User | #2
pet13
New Coder

 
Join Date: Dec 2010
Posts: 17
Thanks: 1
Thanked 0 Times in 0 Posts
pet13 is an unknown quantity at this point
I'm not sure if this is exactly what your looking for, but it might be helpful.

http://download.oracle.com/javase/1....Tokenizer.html
pet13 is offline   Reply With Quote
Reply

Bookmarks

Tags
array, arraylist, java, jsp

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:37 PM.


Advertisement
Log in to turn off these ads.