• 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

Unexpected results from query....

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I'm executing a query which is like:
SELECT USERNAME,USERNO........FROM USER WHERE USERNAME LIKE ?;
I'm using PreparedSatements for this, and passing the value entered by the user. If user wants to search for a name beginning with Ma_, I'm passing 'Ma_%' to the SELECT statement. But I get all rows beginning with Ma, including ones like Ma9189,Ma7594, then I get Ma_744, till Ma_zzz, and Maaaa till Mazzz. I expected to see only usernames beginning with Ma_. Why are all numbers beginning with Ma also shown, and also all user names beginning with Ma not having the underscore ?
Any clarifications will be very helpful.
Thanks.
 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the underscore is also a seach character meaning a single position. so 'MA_' returns MAA, MAB, ...
When you put MA_% you'll end up just like it was MA%
Dan
 
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You should be able to use an escape character or something to get the search you wanted, the specifics might vary from Db to Db.
Also, if you have patterns that contain numbers in the username they will obviously be returned if they match your query.
 
Mallika Kumar
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Daniel and Andrew. Your answers were very helpful.
reply
    Bookmark Topic Watch Topic
  • New Topic