File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difficulties in an IF statement

 
Omar Ali
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 50
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that Java™ code at all?
 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
Omar Ali
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Campbell,

This is a jsp code.

I tried to change the code, but I didn't get the concept well.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 45
Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what do you suggest to sove this issue?
 
Daniel Sagayaraj
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic