Hibernate Query Language-Aggregate function-max
Use:
Sometime we want to get max value from table,at that time we have to use max(aggregate function).
Problem:
To get maximum mark of mathematics from student table in navalady database.
Procedure:
Note: |
|
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 MaxExam
Include following coding into MaxExam
< %@page contentType="text/html" pageEncoding="UTF-8"% >
< !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
http://www.w3.org/TR/html4/loose.dtd >
< %@page import="org.hibernate.SessionFactory" % >
< %@page import="org.hibernate.Session" % >
< %@page import="org.hibernate.cfg.Configuration" % >
< %@page import="org.hibernate.*" % >
< %@page import="java.util.*" % >
< %@page import="Hiber.Student" % >
< html >
< head >
< title > Hibernate Max(aggregate function)Example < /title >
< /head >
< body >
< %
try
{
SessionFactory sessionFactory=new Configuration().configure().buildSessionFactory();
Session s=sessionFactory.openSession();
String sql="select max(tamil) from Student student";
Query query=s.createQuery(sql);
List list=query.list();
out.println("Getting Maximum TAMIL Mark : "+list.get(0));
}
catch(Exception e)
{
out.println(e);
}
% >
< /body >
< /html >
output:
Check the result
Open mysql
Given below query
mysql > select * from Student;
No comments:
Post a Comment