Skip to main content

Findby Login and password Myeclipse Mysql

1 reply [Last post]
smile88
Offline
Joined: 2012-10-03
Points: 0

hello,
I hope you will help me my friends thank you in advance.
First of all I light the software environment: my database is MYSQL , IDE is MyEclipse, Framework Struts and hibernate
I added a method to test the login and password to the class that is already UserDAO.java with myeclipse automatically generated but I have a development error, please help me thank you
code de UserDAO.java

package com.load.hibernate;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

public class UserDAO extends BaseHibernateDAO  {
private static final Log log = LogFactory.getLog(UserDAO.class);
//property constants
public static final String IP_USER = "ipUser";
public static final String NOM_USER = "nomUser";
public static final String PRENOM_USER = "prenomUser";
public static final String EMAIL = "email";
public static final String LOGIN = "login";
public static final String PASSWORD = "password";


    public void save(User transientInstance) {
        log.debug("saving User instance");
        try {
            getSession().save(transientInstance);
            log.debug("save successful");
        } catch (RuntimeException re) {
            log.error("save failed", re);
            throw re;
        }
    }
   
public void delete(User persistentInstance) {
        log.debug("deleting User instance");
        try {
            getSession().delete(persistentInstance);
            log.debug("delete successful");
        } catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }
   
    public User findById( java.lang.Integer id) {
        log.debug("getting User instance with id: " + id);
        try {
            User instance = (User) getSession()
                    .get("com.load.hibernate.User", id);
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }
   
   
    public List findByExample(User instance) {
        log.debug("finding User instance by example");
        try {
            List results = getSession()
                    .createCriteria("com.load.hibernate.User")
                    .add(Example.create(instance))
            .list();
            log.debug("find by example successful, result size: " + results.size());
            return results;
        } catch (RuntimeException re) {
            log.error("find by example failed", re);
            throw re;
        }
    }   
   
    public List findByProperty(String propertyName, Object value) {
      log.debug("finding User instance with property: " + propertyName
            + ", value: " + value);
      try {
         String queryString = "from User as model where model."
         + propertyName + "= ?";
         Query queryObject = getSession().createQuery(queryString);
queryObject.setParameter(0, value);
return queryObject.list();
      } catch (RuntimeException re) {
         log.error("find by property name failed", re);
         throw re;
      }
}

public List findByIpUser(Object ipUser
) {
return findByProperty(IP_USER, ipUser
);
}

public List findByNomUser(Object nomUser
) {
return findByProperty(NOM_USER, nomUser
);
}

public List findByPrenomUser(Object prenomUser
) {
return findByProperty(PRENOM_USER, prenomUser
);
}

public List findByEmail(Object email
) {
return findByProperty(EMAIL, email
);
}

public List findByLogin(Object login
) {
return findByProperty(LOGIN, login
);
}

public List findByPassword(Object password
) {
return findByProperty(PASSWORD, password
);
}
public List findAll() {
log.debug("finding all User instances");
try {
String queryString = "from User";
         Query queryObject = getSession().createQuery(queryString);
return queryObject.list();
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public List findByLoginAddPwd(String login,String pwd){  
      log.debug("finding user instance by login and password");  
      try {  
          String queryString = "from User as user where user.login="+login+",user.password="+pwd;  
          Query queryObject = getSession().createQuery(queryString);  
          queryObject.setParameter(0, login);  
          queryObject.setParameter(1, pwd);  
          return queryObject.list();  
      } catch (RuntimeException re) {  
          log.error("find all failed", re);  
          throw re;  
      }
}
    public User merge(User detachedInstance) {
        log.debug("merging User instance");
        try {
            User result = (User) getSession()
                    .merge(detachedInstance);
            log.debug("merge successful");
            return result;
        } catch (RuntimeException re) {
            log.error("merge failed", re);
            throw re;
        }
    }

    public void attachDirty(User instance) {
        log.debug("attaching dirty User instance");
        try {
            getSession().saveOrUpdate(instance);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
   
    public void attachClean(User instance) {
        log.debug("attaching clean User instance");
        try {
            getSession().lock(instance, LockMode.NONE);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
}

ERROR

javax.servlet.ServletException: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: , near line 1, column 60 [from com.load.hibernate.User as user where user.login=admin,user.password=admin]
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:545)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:486)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

classe AuthentificationAction

/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.load.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.load.hibernate.User;
import com.load.hibernate.UserDAO;
import com.load.struts.form.AuthentifForm;
import java.util.List;

public class AuthentifAction extends Action {

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
AuthentifForm authentifForm = (AuthentifForm) form;// TODO Auto-generated method stub
String map="ko";
String login=authentifForm.getLogin();
String password = authentifForm.getPassword();
List test ;
UserDAO dao =new UserDAO();
test= dao.findByLoginAddPwd(login, password);
System.out.println("test size  = "+test.size());
if(test.size()!=0)
{System.out.println("utilisateur authentifié");
map="ok";}
return mapping.findForward(map);
}
}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
sofistek
Offline
Joined: 2006-02-21
Points: 0

The error message states that there is an unexpected token at column 60. If you count 60 characters in from the start of the query that is in the error message, you get to the character "," which is exactly the same as the token which was unexpected. This should be the word "and", rather than ",".