Win a copy of AWS Security this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Should findByCriteria method return true if searching empty string for criteria[n]

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

The following is the findByCriteria method in the DBAccess interface.


I use the String.startsWith method to judge the condition:

A non-null value in criteria[n] matches any field value that begins with criteria[n]. (For example, "Fred" matches "Fred" or "Freddy"

.

But I found that if the criteria[n] is an empty string, the String.startsWith returns ture.

for example:


My question is if the parameter criteria is array like , should it return the matched record?


 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, Pkinuk!

My question is if the parameter criteria is array like , should it return the matched record?



Well, interesting thing you found out. I myself didn't make such verification. Here's what I did:



So I just verify if it isn't null. In my implementation, this record would be returned.
 
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Robert,

by applying the String method toLowerCase() you realize matching in a case-insensitive style.

Is this a requrement or do you just go fine having just a case-sensitive match without using methods like toUpperCase / toLowerCase?

Regards,
Andy
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have similar code as Roberto.

@Andy: I used the toLowerCase function too. It's not a must requirement, so you don't have to do it at all. But I'd just decided to implement case insensitive searching in my Data class. That's all

Kind regards,
Roel
 
pkinuk Buler
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I also use similar code as Roberto to match the criteria. Since you all can pass the exam by using same theory to implement the findByCriteria method, I don't think I will fail.

Thank you all.

 
You got style baby! More than this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic