• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need Help Iterating though a Result Set

 
Ranch Hand
Posts: 182
1
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I need help to figure something out.
I have a result set
that I need to print it out.
So the query returns something like the result in the picture:
No. Name1 Address Name2
1 Ioanna xx Ioanna
2 Maria         yy Julia
3 Nikos         zz Markos

I want with Java to print out the lines ONLY WHEN Name1 is not equal to Name2.
So if Name1 is equal to Name 2 I don't want to print it out.
I tried this:


The above does not work. What am I doing wrong??
1.JPG
[Thumbnail for 1.JPG]
 
Ranch Hand
Posts: 209
13
VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does your QUERYSELECT look like?

You could put a where clause in there so the server never sends those rows back to the client.
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
True, it can always be filtered from the query itself, you don't need to such complex logic.
 
Ioanna Katsanou
Ranch Hand
Posts: 182
1
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My query is like this:

SELECT No, Name1, Address, Name2 from my_table;
 
Ranch Hand
Posts: 624
9
BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ioanna Katsanou wrote:My query is like this:

SELECT No, Name1, Address, Name2 from my_table;


In this query you can add a "where" clause which will get the records only which you want.
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Now just iterate through though the ResultSet , you don't need any such complex logic.
 
Ioanna Katsanou
Ranch Hand
Posts: 182
1
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Swastik Dey wrote:

Now just iterate through though the ResultSet , you don't need any such complex logic.



Cool thanks a lot !!! I don't know my brain just stuck !! thanks
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are welcome.
 
Marshal
Posts: 79153
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Swastik Dey wrote: . . .

Are you sure that shouldn't read ...Name1 != Name2?
I think this discussion would fit better in our databases forum.
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tend to forget what goes with what language, but I think in SQL it's "Name1 <> Name2".

Although you really shouldn't use uppercase letters in database entity and column names. Some databases can be funny about them.
reply
    Bookmark Topic Watch Topic
  • New Topic