I want to select multiple rows/records from a table, and then put the result into a "variable". Then I want to print each row's content.
If I use hibernate with Java, how can I do that?
For example, I have a student table and I want to get all the rows of the tables. I know each row is an instance of the table/entity class/bean. (assume I have an entity class-student )
The table is like (assume I have a table in database with data):
table name: sutdent
with four colums
id, lname, fname, sex
I remember I can do something like:
List<student> stlist=HibernateUtil.getSession().createQuery("select*from student").list();
//here I want to print the lname of the first row/object
System.out.println(stlist.get(0).getLname(););
Why I get error with message "unexpectesd token * " ?
I cannot use * ? if I cannot use *, if I want to get everything (all the attributes/columns) of a record, what can I do?
or is there any other error? what I should do? Thanks!!
*in production code. Also, you shouldn't make any assumption about the order of columns in the result set when using*.