Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / April 2007

Tip: Looking for answers? Try searching our database.

LIKE escape clause for JDBC

Thread view: 
Mike DiChiappari - 10 Apr 2007 13:48 GMT
I want to do something like:

SELECT * FROM Person WHERE lastname LIKE 'Smit%' or with a PreparedStatement
something a little more dynamic, such as
SELECT * FROM Person WHERE lastname LIKE ?%

I've seen numerous explanations of how to "escape" the percent sign through
JDBC.  Following those examples I've tried:

SELECT * FROM Person WHERE lastname LIKE ?$% {escape $}
SELECT * FROM Person WHERE lastname LIKE '?$%' {escape $}

The problem is those don't work.  Any help would be appreciated.

Mike
Tom Hawtin - 10 Apr 2007 13:59 GMT
> I want to do something like:
>
> SELECT * FROM Person WHERE lastname LIKE 'Smit%' or with a PreparedStatement
> something a little more dynamic, such as
> SELECT * FROM Person WHERE lastname LIKE ?%

Append the '%' to the string either within Java or SQL (LIKE CONCAT(?,
'%')).

Tom Hawtin
Lionel - 16 Apr 2007 13:28 GMT
> I want to do something like:
>
[quoted text clipped - 4 lines]
> I've seen numerous explanations of how to "escape" the percent sign
> through JDBC.

This works with Oracle:
SELECT * FROM Person WHERE lastname LIKE 'Smit!%'


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.