• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

PreparedStatement using LIKE

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

I�m tired of searching the internet for this one


using a PreparedStatement with the query
I also tried other similar ways like:
ps.setString(2, "%" + str2);
ps.setString(2, '%' + str2);
I am not having the right result. I tested with a DB-Tool + I am sure it is not working.

Jamie Robertson wrote in Jamie Comment:


keep in mind that every driver/database combo deals with special characters differently. Some escape all special characters, some escape only single quotes. So you'd have to find out from your jdbc driver documentation how your specific driver handles the special character %. If it escapes it, your search is looking for the % literally. If it doesn't escape it, then it will work as the intended wildcard. The same code used in the example you've linked to works fine as a wildcard search using classes12.zip Oracle drivers to an Oracle 8.1.7 database.


I think that is my case: the code is taking % literally and not using it as a wildCard

the driver is sun.jdbc.odbc.JdbcOdbcDriver
SDK 1.4.1_01
database = sql server

anyone knows how can I deal with it...

thanks + regards,
Javoso
[ August 03, 2004: Message edited by: Javoso Torso ]
 
Javoso Torso
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
got something work!:



there are rumors that some mssql drivers have a bug that makes setString() not work with "LIKE"

So, that's my contribution for all the people looking for hours for a solution...

Regards,
Javoso
[ August 03, 2004: Message edited by: Javoso Torso ]
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for posting the follow-up!
 
reply
    Bookmark Topic Watch Topic
  • New Topic