• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can PreparedStatements take care of this ?

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Thomas Paul. I'll try it out.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic