smile88 | bonjour,
j'espère bien que vous m'aider mes amis et merci d'avance.
tout d'abord j’éclaire l'environnement logiciel:
ma base donnée est MYSQL et j’utilise MYEclipse 10 et j'ai intégré les frameworks struts et hibernate
j'ai ajouté une methode qui test le Login et le password findByLoginAddPwd(String login,String pwd) à la classe UserDAO.java qui est déjà généré automatiquement avec myeclipse mais j'ai un erreur de developpement, veuillez bien m'aider merci
voisi le code de UserDAO.java
Code :
- 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;
- }
- }
- }
|
l'erreur:
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)
et la classe AuthentificationAction
Code :
- /*
- * 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);
- }
- }
|
|