From the course: Java Database Access with Hibernate

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Named parameters

Named parameters - Java Tutorial

From the course: Java Database Access with Hibernate

Start my 1-month free trial

Named parameters

- [Instructor] Have you ever used named parameters in a JDBC query? in a JDBC query? We can also use named parameters in an hql type of query. Hql, using named parameters, enforces data integrity. It allows us to use user input in our queries with limited risk of malicious intent from the user. Let's take a look at an example. Let's try to find employees who have a salary greater than 50,000 dollars. Let's start by creating a string that'll represent our query. So this time I'm going to do string hql is equal to from employee where salary is greater than, is equal to from employee where salary is greater than, and this is where I'm going to put my named parameter. I use a colon and then the variable name, salary. You know, my query. I'm going to do session.createQuery. I'm going to erase this, and I'm going to use the variable, hql, cause that has my query. Next, I'm going to actually set my salary to a value. Since I'm not asking the user to enter a value, I'm just going to hard code…

Contents