Hibernate HQL query by using like operator.

Hibernate HQL query by using like operator.

How use like operator in HQL?

View Answers

May 31, 2012 at 6:50 PM

HQL stands for Hibernate Query Language, provided by Hibernate. It is minimal object oriented, similar to SQL.It works like a bridge between database and application. Like operator is used for string pattern matching. The percent character(%) is used before or after the character/substring.

package net.roseindia.main;

import java.util.*;
import net.roseindia.table.Employee;
import net.roseindia.util.ConnectionUtil;
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;

public class MainClass {
    public static void main(String[] args) {
        SessionFactory sessionFactory = ConnectionUtil.getSessionFactory();
        Session session = sessionFactory.openSession();

        String hql="SELECT emp.name, emp.salary, emp.dateOfJoin from Employee emp WHERE emp.name like 'R%'";
        Query query=session.createQuery(hql);
List<Object> objectList = query.list();
        Iterator iterator = objectList.iterator();
        while(iterator.hasNext()){          
            Object []obj = (Object[])iterator.next();
            System.out.println(obj[0]);
            System.out.println(obj[1]);
            System.out.println(obj[2]);
        }

        session.close();
    }
}

Ads









Related Tutorials/Questions & Answers:
Hibernate HQL query by using like operator.
Hibernate HQL query by using like operator.  How use like operator in HQL?   HQL stands for Hibernate Query Language, provided by Hibernate... database and application. Like operator is used for string pattern matching
Case-insensitive search using Hibernate Query Language(HQL).
Case-insensitive search using Hibernate Query Language(HQL).  What is Case-insensitive search using Hibernate Query Language
Advertisements
Delete Query using HQL
Delete Query using HQL  Can we write 'AND' with 'WHERE' clause in delete query using HQL? For example: delete from table name where field1... a look at the following link: Hibernate Delete Query
What is Hibernate Query Language (HQL)?
What is Hibernate Query Language (HQL)?  Hi, What is Hibernate Query Language (HQL)? thanks
HQL, Hibernate Query Language
HQL - Hibernate Query Language In this tutorial on HQL we will learn how...? The HQL stands for Hibernate Query Language, which is inspired by the SQL... the programmer to write Query using the persistence entity. The HQL is fully
Hibernate Like Query
This section illustrate hibernate like query with example
How to use AND operator in hibernate Detached criteria query?
How to use AND operator in hibernate Detached criteria query?  How to use AND operator in hibernate Detached criteria query
HQL in hibernate ? Explain the use of HQL.
HQL in hibernate ? Explain the use of HQL.  What is the HQL in hibernate ? Explain the use of HQL.   HQL stands for Hibernate Query... like SQL.Its query is case-insensitive expect we are using the java class
How to use AND OR operator in hibernate Detached criteria query?
How to use AND OR operator in hibernate Detached criteria query?  How to use AND OR operator in hibernate Detached criteria query?   You can use AND, OR operator in hibernate detachedCriteria through
HQL Query
HQL Query  Hibernate query language: How to use a left join in Hibernate query language. Can somebody help with an example. I am getting a unexpected token error in HQL Query tool If I use joins
like operator
like operator  how to select exact value using like operator in php
Introduction To Hibernate Query Language (HQL)
Introduction To Hibernate Query Language (HQL) In this tutorial you will learn about Hibernate Query Language. HQL is an abbreviation of Hibernate Query... as roseindia.net.Hibernateexample. Benefits of Hibernate Query Language is : Learning (HQL) Query
How to use OR operator in hibernate Detached criteria query?
How to use OR operator in hibernate Detached criteria query?  How to use OR operator in hibernate Detached criteria query?   You can use OR operator in hibernate detachedCriteria through Restrictions.disjunction
HQL query
HQL query  how to select only password based on username using HQL query from login table where uname and paswrd are two column names
LIKE Operator
SQL Like Operator Query Now we want to select the persons name those name... LIKE Operator       The LIKE operator is used for searching  a specified pattern
select query using hibernate
select query using hibernate  Hi, can any one tell me to select records from table using hibernate. Thanks   Please visit the following link: Hibernate Tutorials The above link will provide you different
Hibernate Query Language
Hibernate Query Language           Introduction to Hibernate Query Language Hibernate Query Language or HQL for short is extremely powerful query language. HQL
how to search for string using LIKE operator instead of integer?
how to search for string using LIKE operator instead of integer?  ... "table2" details. in other words, my "dbtable.jsp" query should be like this (select * from items where itemname LIKE '"+id). and my detail file "table2.jsp
PHP SQL LIKE Operator
PHP SQL LIKE Operator       This example illustrates how to use the like operator in sql query. The LIKE operator is used in a WHERE clause to search for  matching strings based
OR operator in hibernate.
OR operator in hibernate.  How to use OR operator in hibernate
AND operator in hibernate.
AND operator in hibernate.  How to use AND operator in hibernate
Hibernate criteria query using Max()
Hibernate criteria query using Max()  What is Hibernate criteria query using Max()?   You can find out maximum value in hibernate criteria by using projection. Projection is an interface and a class
Hibernate criteria query using Min().
Hibernate criteria query using Min().  How to find minimum value in Hibernate criteria query using Projection?   You can find out minimum value in hibernate criteria by using projection. Projection is an interface
Hibernate criteria query using avg()
Hibernate criteria query using avg()  How to calculate average in Hibernate criteria query using Projection?   You can calculate average of any numeric values in hibernate criteria by using projection. Projection
HQL Query in execute method of Struts2
data from database using hql. And where I need to write the hql query...HQL Query in execute method of Struts2  I am making login page in struts2 and using hibernate . Now I wants to pull user name and password from
PHP SQL LIKE Operator
PHP SQL LIKE Operator This example illustrates how to use the like operator in sql query. The LIKE operator is used in a WHERE clause to search... like 's%'"); In this query we want to find the name which end with h
Mysql Like Operator
Mysql Like Operator       Mysql Like Operator is used to compare a part of string using...) Query to view data from Table named employee1 using like command
Mysql Like Operator
Mysql Like Operator       Mysql Like Operator is used to compare a part of string using the % wild... to view data from Table named employee1 using like command: The below Query
LIKE Operator
Like Operator Query Now we want to select the persons name those name starts... LIKE Operator       The LIKE operator is used for searching  a specified pattern
HQL
HQL  What is the HQL in hibernate ? Explain the use of HQL.   Hi Friend, Please visit on this link....... Hibernate Query Language
Hibernate delete Query
Hibernate delete Query In this tutorial you will learn how to use HQL delete query in Hibernate. In this section we are discussing about the HQL delete query... to use HQL delete query. An example is being given regarding how delete query may
sum and avg function using HQL.
sum and avg function using HQL.  How to use sum and avg function in HQL?   HQL supports many aggregate functions. Sum and avg are some...(emp.salary) FROM Employee emp"; Query sumQuery = session.createQuery
Hibernate Query Language
Hibernate Query Language   Explain Hibernate Query Language(HQL) of Hibernate?   Hi Samar, Hibernate Query Language is a library.... Compared with SQL, however, HQL is fully object-oriented and understands notions
Mysql Like Operator
of pattern matching in select query. The like comparison Operator in SQL allows you... Mysql Like Operator     ... to understand an  example from 'Mysql Like Operator'.To grasp this exammple we create
Mysql Like Operator
in select query. The like comparison Operator in SQL allows you to match any... Mysql Like Operator      ... from 'Mysql Like Operator'.To grasp this exammple we create a table'employee1
Using Min, Max and Count on HQL.
Using Min, Max and Count on HQL.  How to use Min, Max and Count on HQL
SQL AND Like Operator
SQL AND Like Operator       The SQL AND Like Operator work with WHERE clause to find and search  for a specified pattern in a column of table. The AND Like Operator
How to get unique list in Hibernate using Criteria Query?
How to get unique list in Hibernate using Criteria Query?  Hi, Share me the example code for getting Unique List in Hibernate through Criteria Query? Thanks
HQL Sample
technical stuff very easily. The HQL or Hibernate Query language is very powerful and can be easily used to develop complex query in Java program. HQL is then translated into SQL by the ORM component of Hibernate. HQL is very powerful
Hibernate Named Native SQL Query using XML Mapping
In this section, you will learn Named Native SQL Query using XML Mapping in Hibernate with an example
Examples of Hibernate Criteria Query
Criteria Query: HQL - Hibernate Query Language Hibernate criteria avg..., HQL Select Example, HQL Select Query Hibernate Tutorials: Hibernate...Example code and running projects of Hibernate Criteria Query Here
Hibernate Query Language
to Hibernate Query Language Hibernate Query Language or HQL for short is extremely powerful query language. HQL is much like SQL and are case...Hibernate Query Language      
like query and then update or replace
like query and then update or replace   In postgres i use like query... "Small state in wmost Brazil bordered by sw Amazonas, Peru, and Bolivia." with like query i can find text that contains text "wmost" after finding that i want
SQL AND Like Operator
SQL AND Like Operator       The SQL AND Like Operator work with WHERE clause to find and search  for a specified pattern in a column of table. The AND Like Operator
Hibernate insert Query
Hibernate insert Query In this tutorial you will learn about how to use HQL insert query. INSERT query in HQL is used to insert the records into the database table. INSERT query of HQL is just like the INSERT query used in SQL
Hibernate Named HQL using XML Mapping
In this section, you will learn executing Named HQL written in XML Mapping file
Hibernate Query Checker
Hibernate Query Checker  How in Hibernate. We can control that programmer should not make query which hang the system. Like table having more the 20 million of data. Query must have where clause
hibernate delete query :
hibernate delete query :   Hi, I m using Hibernate 3 + javadb my table is like: CREATE table APP.BIDS ( BID_ID INTEGER NOT NULL... APP.BIDS where BID_ID = 16"; Query query = session.createQuery(query1); int row
Hibernate criteria query
Hibernate criteria query  Hi... I need criteria query like query... a.countryId=c.Chrono and a.groupId=b.Chrono and a.type =1 "); like this in hibernate...: http://www.roseindia.net/hibernate/criteriaqueyexample.shtml
Criteria Query Examples in Hibernate
Criteria Query Examples in Hibernate  How to use the Criteria Query in Hibernate? How to select the data using Criteria Query of Hibernate? Thanks... Criteria Query in Hibernate with Examples code. Check the tutorial Criteria Query

Ads