Hibernate Criteria Expression- equal
Aim:
To learn how to use equal in our hibernate.
Problem:
To get stuname (jagan) records using equal.
Solution:
Step 1:
Create Hibernate Reverse Engineering wizard
Step 2:
Create HibernateUtil.java
Step 3:
Create POJO class and mapping files
Step 4:
Create jsp file named as EqualExp.jsp
Include following coding into the EqualExp.jsp
< %@page import="Hiber.Student"% >
< %@page import="org.hibernate.*" % >
< %@page import="org.hibernate.cfg.*" % >
< %@page import="org.hibernate.criterion.*" % >
< %@page import="Hiber.Student" % >
< %@page import="java.util.*" % >
< %@page contentType="text/html" pageEncoding="UTF-8"% >
< html >
< head >
< title > Hibernate Criteria Expression Equal < /title >
< /head >
< body >
< %
try
{
SessionFactory sf=new Configuration().configure().buildSessionFactory();
Session ss=sf.openSession();
Criteria c=ss.createCriteria(Student.class);
c.add(Expression.eq("stuname","jagan"));
List list=c.list();
Iterator it=list.iterator();
while(it.hasNext())
{
Student s=(Student)it.next();
out.println(s.getStuname());
out.println(s.getStuno());
out.println(s.getTamil());
out.println(s.getEnglish());
out.println(s.getMaths());
out.println(s.getScience());
out.println(s.getSocialscience());
out.println(s.getJoindate());
}
}
catch(Exception e)
{
}
% >
< /body >
< /html >
Output:
To manually check using mysql query.
mysql > select * from student where stuname=’jagan’;
No comments:
Post a Comment