Meaningless Drivel is fun!*
The moose likes JDBC and the fly likes Can PreparedStatements take care of this ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Can PreparedStatements take care of this ?" Watch "Can PreparedStatements take care of this ?" New topic
Author

Can PreparedStatements take care of this ?

Mallika Kumar
Ranch Hand

Joined: Feb 15, 2001
Posts: 61
Hi,
I need to create a query string based on these conditions. I'd like my query string to be as follows in SQL++:
SELECT * FROM TABLENAME WHERE TABLECOLUMN LIKE '%abc%';
I'd like to compare the user-entered column value and match it in the table rows. If I try to use this in a PreparedStatement in a similar way, like :
SELECT * FROM TABLENAME WHERE TABLECOLUMN LIKE '%?%'
I get SQL errors saying that the string has not been terminated correctly, or it does not give me rows in the table, which do match and exist.
I can achieve this by using Statements and using '%' + column_value, but is there a way to do this with PreparedStatements ?
Any response will be very helpful.
Thanks.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Use:
SELECT * FROM TABLENAME WHERE TABLECOLUMN LIKE ?
and include the %'s as part of the String.
------------------
Moderator of the JDBC Forum


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Mallika Kumar
Ranch Hand

Joined: Feb 15, 2001
Posts: 61
Thanks a lot Thomas Paul. I'll try it out.
 
 
subject: Can PreparedStatements take care of this ?
 
Similar Threads
how to count rows
Is it possible to view the SQL that got executed?
using wildcards literally in queries
help with getting the table name from the user input
Retrieving a subset of rows with SQL