| Author |
Should findByCriteria method return true if searching empty string for criteria[n]
|
pkinuk Buler
Ranch Hand
Joined: May 22, 2009
Posts: 57
|
|
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?
|
 |
Roberto Perillo
Bartender
Joined: Dec 28, 2007
Posts: 2212
|
|
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.
|
Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
|
 |
Andy Jung
Ranch Hand
Joined: Feb 07, 2010
Posts: 150
|
|
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
|
SCJP, SCJD
|
 |
Roel De Nijs
Bartender
Joined: Jul 19, 2004
Posts: 4349
|
|
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
|
SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
|
 |
pkinuk Buler
Ranch Hand
Joined: May 22, 2009
Posts: 57
|
|
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.
|
 |
 |
|
|
subject: Should findByCriteria method return true if searching empty string for criteria[n]
|
|
|