Q:

Implementing Search function - eclipselink SQL with string as parameter and wildcard %

I am having difficulties using the eclipselink syntax in an SQL query for my website. Currently, I have created a search text-box entry with an appropriate button. Data records are able to be searched by title and description, however the search content must match identically the titles/descriptions in my database data. My main issue is creating the correct SQL query using the LIKE clause with the parameter "searchString" and the wildcard functionality (%). 
Below, I have included a sample of my query from the entity class. 
@NamedQuery(name = "Ad.findByString", query = "SELECT a FROM Ad a WHERE a.title LIKE :searchString OR a.description LIKE :searchString")

I understand the ":" mark indicates a parameter is being used. Does anyone have any suggestions for how to implement the wildcard % functionality in order for searches to return Ads containing the search content?
Below I have also included my getSearchedAds method from by database class
public static Collection <Ad> getSearchedAds (String searchString) {
        EntityManager em = DBUtils.getEmFactory().createEntityManager();
        Collection<Ad> results = null;

        TypedQuery<Ad> q = em.createNamedQuery("Ad.findByString", Ad.class);
        q.setParameter("searchString", searchString);

        try {
            results = q.getResultList();

        } catch (Exception e) {
            results = null;
        }

Thank you for your time.

A:

I believe you need to concatenate the db-wildcard character to the searchString before you set it as a parameter to the query:
searchString = "%" + searchString + "%";
q.setParameter("searchString", searchString);

and keep the NamedQuery as-is.

