开发者

How to check for case sensitive in hibernate criteria

0 vote down star

I have used hibernate to fetch the login information from the mysql database. But the probl开发者_JS百科em is that say for example the user name is 'dhiraj' in the database, now the login is successful by entering the user name, but it is also allowing to enter by taking the user name in uppercase also, e.g., 'DHIRAJ'. I want to restrict it to as it in the database. Can you tell me how to achieve that in hibernate?


I don't think hibernate is the matter here.

What database are you using ? (you should retag your question to add at least the db implementation you are using).

For example mysql do not do case sensitive comparison by default. Look here : http://mysqldatabaseadministration.blogspot.com/2006/09/case-sensitive-mysql.html on how to make mysql do case sensitive comparison.

EDIT: like said in the link i've pasted, you can do it at the table creation, by setting a special character set, like that :

###########
# Start case sensitive collation example
###########

mysql> create table case_cs_test (word VARCHAR(10)) CHARACTER SET latin1 COLLATE latin1_general_cs;
Query OK, 0 rows affected (0.08 sec)

mysql> INSERT INTO case_cs_test VALUES ('Frank'),('Google'),('froogle'),('flickr'),('FlicKr');
Query OK, 5 rows affected (0.00 sec)
Records: 5  Duplicates: 0  Warnings: 0

mysql> SELECT * FROM case_cs_test WHERE word  LIKE 'F%';
+---------+
| word    |
+---------+
| Frank   |
| FlicKr  |
+---------+
4 rows in set (0.00 sec)

mysql> SELECT * FROM case_cs_test WHERE word  LIKE 'f%';
+---------+
| word    |
+---------+
| froogle |
| flickr  |
+---------+
2 rows in set (0.00 sec)

###########
# end
###########
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜