aspose file tools*
The moose likes JSP and the fly likes Difficulties in an IF statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Difficulties in an IF statement" Watch "Difficulties in an IF statement" New topic
Author

Difficulties in an IF statement

Omar Ali
Greenhorn

Joined: Dec 23, 2008
Posts: 15
Hello All,

I am having difficulties while preparing a jsp report. Here is how does it look:

Name Item

Kane 123
Kane 333
Kane 434
Kim 444
What I am trying to do is that group by Name

Kane 123
333
434
Kim 444
If the next name = the previous name then hide the name, otherwise show the name.

Here is my code:



The above code is not showing what I want, so how do I change the code and do a group for each name.

Thanks for your help
Stephan Mueller
Ranch Hand

Joined: May 05, 2010
Posts: 50


think about what you are comparing there. hint: it's not what you expect it to be.
Edit: on a second look, think about what rs.next() does and how this screws up your code.


1. Make it run - 2. Make it run correctly - 3. Make it pretty OR fast/small - 4. ??? - 5. Profit
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36452
    
  15
Is that Java™ code at all?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36452
    
  15
And welcome to the Ranch
Omar Ali
Greenhorn

Joined: Dec 23, 2008
Posts: 15
Hello Campbell,

This is a jsp code.

I tried to change the code, but I didn't get the concept well.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36452
    
  15
I think I had best transfer this thread to the JSP forum. (It will be visible here for, I think, one week).
Smitesh Shinde
Ranch Hand

Joined: Feb 16, 2008
Posts: 45

Omar,

First thing in modern practice it is not advised to put your Java Code inside JSP page.

Now about your problem you cannot call equals method on boolean primitive. Your code should not compile in first place.
Omar Ali
Greenhorn

Joined: Dec 23, 2008
Posts: 15
So what do you suggest to sove this issue?
Daniel Sagayaraj
Ranch Hand

Joined: Mar 15, 2010
Posts: 32
import java.util.ArrayList;
import java.util.Iterator;

public class temp {

public static void main(String[] args) {

//Replace myList with your ResultSet
ArrayList myList = new ArrayList();
myList.add("Daniel");
myList.add("Kumar");
myList.add("Google");
myList.add("Working");
myList.add("Daniel");
myList.add("RAMKUMAR");
myList.add("RAMKUMAR");
myList.add("HELP");
myList.add("Yamuna");
myList.add("Daniel");

Iterator iterator = myList.iterator();
ArrayList printedList = new ArrayList();

while (iterator.hasNext()) {

String printValue = (String) iterator.next();
if (!printedList.contains(printValue)) {
System.out.println(printValue);
printedList.add(printValue);
}

}

}
}
------------------------

Output::

Daniel
Kumar
Google
Working
RAMKUMAR
HELP
Yamuna
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difficulties in an IF statement
 
Similar Threads
Getting the TD value using JavaScript + TD does not contain any ID.
Display output table
Logic for dealing with resultSet
passing values from javascript to jsp and vice versa
JSP attendance management project error