Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to Exclude one record from Query?  RSS feed

 
Samar Land
Ranch Hand
Posts: 68
1
  • Mark post as helpful
  • send pies
  • 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?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
I'm looking for a way without modify my query.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why? It's the right way to do it.
 
Stefan Evans
Bartender
Posts: 1836
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
I solved it by adding this to my query.

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!