Hibernate Query Language-where clause
Use:
We get records depending upon the given condition using where clause.
Problem:
To get student name who have passed in tamil.
We assume that the pass mark is above 50.
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 WhereExam
Include following coding into WhereExam
< %@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 where clause Example < /title >
< /head >
< body >
< %
try
{
SessionFactory sessionFactory=new Configuration().configure().buildSessionFactory();
Session s=sessionFactory.openSession();
String sql="select stuname from Student student where tamil>50";
Query query=s.createQuery(sql);
List list=query.list();
out.println("Students who have passed in Tamil/n");
for(int i=0;i
Check the result
Open mysql
Given below query
mysql > select stuname from Student where tamil>50;
No comments:
Post a Comment