wood burning stoves 2.0*
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Can PreparedStatements take care of this ?