This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes Taking entries from database containing % Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Taking entries from database containing %" Watch "Taking entries from database containing %" New topic

Taking entries from database containing %

Raj Kumar Bindal
Ranch Hand

Joined: Apr 15, 2006
Posts: 418
I want to take entries from database having % ,how to do that
I am doing:
select * from tablename where columnname like '%%'
but not working
How can i achieve that
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3749

I believe it varies on the DBMS but since % is a special character, if you want to reference it as a literal you need to use something like \% (MySQL usage).

For example if you wanted to find all rows with a column that contains a %, the query would be:

Note the % before and after \% for wildcard matching.

[OCA 8 Book] [Blog]
Naveen Mishra
Ranch Hand

Joined: Nov 20, 2005
Posts: 75
The same is true for Oracle and DB2 as well.
It is sorta covered in the JavaRanch Style Guide.
subject: Taking entries from database containing %
It's not a secret anymore!