NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Need Help Please! Want to pass a input param to entitymanager and query result back to servlet

 
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users
View previous topic :: View next topic  
Author Message
kwesiaryee



Joined: 27 Jul 2009
Posts: 4

PostPosted: Mon Jul 27, 2009 12:35 pm    Post subject: Need Help Please! Want to pass a input param to entitymanager and query result back to servlet Reply with quote

I am trying to use persistence as my data layer. I am developing a login account page with where username and password will be checked before its logged in. I have passed the input strings to the entity manger and return the result to a servlet. but it doesn't seem to work. This is the code
Code:
public Users getMyUsers(String username, String password) {
        try {
            Context ctx = new InitialContext();
            UserTransaction utx = (UserTransaction) ctx.lookup("java:comp/env/UserTransaction");
            utx.begin();
            EntityManager em = (EntityManager) ctx.lookup("java:comp/env/persistence/LogicalName");
            Query q = em.createQuery("SELECT u FROM Users u WHERE u.username = :username AND u.password = :password");
            q.setParameter(username, q);
        } catch (Exception e) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", e);
            throw new RuntimeException(e);
        }
        return q;
    }


Please i need help on this ... Thanks
Back to top
Melongo Annabel
Posted via mailing list.





PostPosted: Wed Jul 29, 2009 1:44 am    Post subject: Need Help Please! Want to pass a input param to entitymanager and query result back to servlet Reply with quote

For someone to help, it would be really helpful to provide a stack trace. Thanks.


From: kwesiaryee <address-removed>
To: address-removed
Sent: Monday, July 27, 2009 7:35:56 AM
Subject: [nbj2ee] Need Help Please! Want to pass a input param to entitymanager and query result back to servlet

I am trying to use persistence as my data layer. I am developing a login account page with where username and password will be checked before its logged in. I have passed the input strings to the entity manger and return the result to a servlet. but it doesn't seem to work. This is the code
Code:
public Users getMyUsers(String username, String password) {

try {

Context ctx = new InitialContext();

UserTransaction utx = (UserTransaction) ctx.lookup("java:comp/env/UserTransaction");

utx.begin();

EntityManager em = (EntityManager) ctx.lookup("java:comp/env/persistence/LogicalName");

Query q = em.createQuery("SELECT u FROM Users u WHERE u.username = :username AND u.password = :password");

q.setParameter(username, q);

} catch (Exception e) {

Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", e);

throw new RuntimeException(e);

}

return q;

}





Please i need help on this ... Thanks
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo