• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can PreparedStatements take care of this ?

 
Mallika Kumar
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use:
SELECT * FROM TABLENAME WHERE TABLECOLUMN LIKE ?
and include the %'s as part of the String.
------------------
Moderator of the JDBC Forum
 
Mallika Kumar
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Thomas Paul. I'll try it out.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic