문제

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top