• 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

How to Exclude one record from Query?

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

I have a current search By Name for users form, It's working just fine.

What I would to do is to exclude one of my result to be showed up

Let say I have this table,

FName LName Address
Samar Land WI
Matt Lero WI
Dany Land WI

When I do search for land, the normal results it will be Samar & Dany
Or If I do Dany, result will be Dany Land

What I want is not displaying Dany at all in my result.

So, What it comes to my mind, that I can add as an if statement in JSP page for



it didn't work like this way, Any other suggestions to make it here?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're doing it backwards. If you don't want certain records to display, don't fetch them from the database in the first place. Use a where clause on your query to filter the results to only those that will be displayed.

The JSTL in the JSP is most certainly not the place to be doing this.
 
Samar Land
Ranch Hand
Posts: 68
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm looking for a way without modify my query.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why? It's the right way to do it.
 
Bartender
Posts: 1845
10
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I noticed that your commented out <c:if> statement was invalid.

Instead of
Try

The EL expression should be the whole expression, including the static string value.

I would echo Bear in saying that it would be preferable to do the filtering in java code - either in your query, or whatever code is processing the results of the query to put it into your user list.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, failing doing it in the query (as is appropriate), then at minimum it should be handled in model or controller code. The view is no place to be doing this sort of thing.
 
Samar Land
Ranch Hand
Posts: 68
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I solved it by adding this to my query.

 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good to see that you are dealing with it at the query level. But that seems rather specific. Have you considered what would be needed if the excluded string where to change? Or if you needed to exclude on multiple strings? You might want to investigate the "in" clause.
 
Samar Land
Ranch Hand
Posts: 68
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What I figured out to do so far here is adding a properties file with the exclude list, then add it to my query

exempt.properties
students =Samar,Dan

Then I had to add the following to my query:

Add the method:


Hope that will help the others

I think the title of my thread should be changed.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Samar Land wrote:I think the title of my thread should be changed.


What would you suggest?
 
Samar Land
Ranch Hand
Posts: 68
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:

Samar Land wrote:I think the title of my thread should be changed.


What would you suggest?



Maybe something like:

How to Exclude one record from Query?
 
Joel Salatin has signs on his property that say "Trespassers will be Impressed!" Impressive tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic