0

im using hibernate with my jsp page and mySQL ,how can i do that select * from student wher userName = *** with HQL

and how i chek if that username exist in 'Student' table ?

in my sql i use that

ResultSet resultat = statement.executeQuery();

if (resultat.next()) { ....}

i try this

Session hibernateSession = MyDB.HibernateUtil.currentSession(); 
hibernateSession.find("select xxx from Etudinat where p.Nom=xxxx");

its give me a list but

i have a login form send me a username and password

i want to chek if that username exist in the table Student to set the user on a session

what is the safty way to do that

0

1 Answer 1

3

I could not paste code into the comment. Try the following HQL:

from Etudinat where Nom = 'xxxx'

Even better, pass the username as a parameter.

Per OP request, code snippet based on the comments:

    Query q = hibernateSession.createQuery("from Etudinat where Nom = :username");
q.setParameter("username", xxxx);       
Etudinat e = q.uniqueResult();
Sign up to request clarification or add additional context in comments.

2 Comments

@David: absolutely not. This why I suggest passing username as a parameter. You can tell session to create a Query using HQL with parameter (where Nom = :username) and set parameter username to the value passed to your DAO. Then you can call uniqueResult() method on your query.
thank you , plz give me a ligne how to use the uniqueResult() i'v to that for tomorow

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.