Hibernate Criteria Expression- greater than
Aim:
To learn how to use greater than in our hibernate.
Problem:
To get stuname from table student in navalady database who get greater than 70 marks in tamil using greater than criteria expression.
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 GreaterThan.jsp
Include following coding into the GreaterThan.jsp
< %@page import="org.hibernate.*" % >
< %@page import="org.hibernate.cfg.*" % >
< %@page import="org.hibernate.criterion.*" % >
< %@page import="java.util.*" % >
< %@page import="Hiber.Student" % >
< html >
< head >
< title > Hibernate Criteria Expression-Greater Than < /title >
< /head >
< body >
< %
try
{
SessionFactory sessionFactory=new Configuration().configure().buildSessionFactory();
Session s=sessionFactory.openSession();
Criteria c=s.createCriteria(Student.class);
c.add(Expression.gt("tamil",new Integer("70")));
List list=c.list();
Iterator it=list.iterator();
while(it.hasNext())
{
Student s1=(Student)it.next();
out.println(s1.getStuname());
}
}
catch(Exception e)
{
out.println(e);
}
% >
< /body >
< /html >
Output:
To check using mysql using following query
mysql > select stuname from student where tamil > 70;
No comments:
Post a Comment