users@glassfish.java.net

Re: setparameter x2

From: Lance J. Andersen <Lance.Andersen_at_Sun.COM>
Date: Fri, 08 Jan 2010 17:58:24 -0500

If i understand your question, you would do something like the following

Query query = em.createQuery(
                "SELECT e.id, e.firstName, e.lastName FROM Employee e
where e.deptName= "deptName and e.state= :state");
        query = query.setParameter("deptName", "JPA");
        query = query.setParameter("state", "MA");

        List<Object[]> rows = query.getResultList();
        for (Object[] row : rows) {
            System.out.println("id=" + row[0] + ",First Name=" + row[1] +
                    ",Last Name=" + row[2]);
        }


Regards
Lance

Eve Pokua wrote:
> Hello everyone,
>
> How do I set 2 parameters which I need to use to pass it
> on to the find method. E.g finding a user name and password
> for a particular user.
>
> public User findUserId(Long userlid){
> User user=new User();
> try{
> user=em.find(Baleent.class, balid);
> }catch(Exception ex){
> System.err.println("Can not access DB");
> }
> return user;
> }
>
> The above method would just return the user's Id. I need to find
> both the user Id and the password with the userid and password
> provided by the user.
>
> E.g
>
> public void userLogin(Long id, String pwd){
>
> "Select userId, pawd from User where userId=id and pawd=pwd"
>
> }
>
> How do I do this with jsql.
>
> Thanks
>
> eve
>
> ------------------------------------------------------------------------