user1948909
user1948909

Reputation:

How do fire a query in hibernate and then access the returned records

I have this query that I want to fire using Hibernate but I do not know the next step and I want to how to run this query and what is the result going to be in the format of and how do I access the contents.

String SQL_QUERY="select emp.ID, emp.password from employee where username=:username";
Query query=session.createQuery(SQL_QUERY);
query.setString("username", username);//How do i fire this query

How do I catch what has been returned and how I do I iterate through the contents that have been returned.

Upvotes: 0

Views: 560

Answers (2)

Mason T.
Mason T.

Reputation: 1577

I suggest reading the hibernate API to understand the different ways to retrieve and use data. I will include the link below.

http://docs.jboss.org/hibernate/orm/3.2/api/org/hibernate/Query.html

Upvotes: 0

Balaji Reddy
Balaji Reddy

Reputation: 5710

String SQL_QUERY="select emp.ID, emp.password from employee where username=:username";
Query query=session.createQuery(SQL_QUERY);
query.setString("username", username);//How do i fire this query

List list = query.list();

Upvotes: 1

Related Questions