how to add a wildcard characters in hibernate?
I have try to do like this but already have a errors
"from Employee where epf like"+Epf+"%";
Epf is a int parameter pass to the query
You missing quotes '...'
. The end-query should look like:
SELECT Employee WHERE epf LIKE 'text%'
so changing your code to
"from Employee where epf like '"+Epf+"%'";
should do the trick. Note: open and close single quotes '
...'
here '"+Epf+"%'
But you approach is not good. Adding text like this to a query is dangerous. Consider this for more information:
It is much safer to use bind parameters:
session.createQuery("from Employee where epf like :epf")
.setParameter("epf", epf + "%")
.list();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With