aspose file tools*
The moose likes JDBC and the fly likes PreparedStatement using LIKE Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "PreparedStatement using LIKE" Watch "PreparedStatement using LIKE" New topic
Author

PreparedStatement using LIKE

Javoso Torso
Ranch Hand

Joined: Aug 15, 2003
Posts: 88
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 ]

I hate 'trial and error'<br />and I am doing it all the time
Javoso Torso
Ranch Hand

Joined: Aug 15, 2003
Posts: 88
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 ]
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Thanks for posting the follow-up!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: PreparedStatement using LIKE