سؤال

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