setparameter x2

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

setparameter x2

eveeve
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


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: setparameter x2

Lance J. Andersen
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


Loading...