简体   繁体   中英

JPQL statement not working with Quotations

I'm trying to print a list (of only 1 item) but my JPQL statement isn't working due to quotations. I've tried every combination possible it seems but none will work. If anyone has any suggestions or different approaches I'd appreciate it. Note: I found a somewhat similar question on the site before I posted this but the answers aren't working for my case. Thanks

String submittedName=request.getParameter("name");
user=entityManager.find(user.getClass(),submittedName);
        Query myQuery=entityManager.createQuery
                ("SELECT u.password FROM UserData u WHERE u.name=''"+submittedName+"");
        List results=myQuery.getResultList();
        String convertedResults=results.get(0).toString();
        out.println(results);

To summarize what Dennis and Rob are trying to say:

String submittedName=request.getParameter("name");
user=entityManager.find(user.getClass(),submittedName);
Query myQuery=entityManager.createQuery("SELECT u.password FROM UserData u WHERE u.name=:name");
myQuery.setParameter("name", submittedName);
List results=myQuery.getResultList();
String convertedResults=results.get(0).toString();
out.println(results);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM