• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to make SELECT statement case sensitive?

 
Timothy Sam
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have the following code...




when I try to invoke

checkUsernamePassword(request.getParameter("username"), request.getParameter("password");

it runs ok, but I noticed that my query behaves in a non-case sensitive manner. How can I make it case sensitive? Thanks!
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't say which database you are using so this might not be right for you, but you can use an UPPER function to force both the field and the bind values to be upper case, e.g. :

Or you could configure your database to be cased insensetive.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the JDBC Forum.
 
Timothy Sam
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


but this would make my query case insensitive... I don't think that is advisable when querying password fields right? I need it to be case sensitive like...

HELLO is not the same as hello...
 
Scott Selikoff
author
Saloon Keeper
Posts: 4014
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree, the proposed solution is the opposite of what you want. The problem is actually with the database itself. Some databases can be configured to perform case insensitive matching or not, and you need to check the database settings for this. I don't recall whether or not this configured on a table/field level granularity, you'd have to consult your database software.

One alternate solution is to perform the query than perform the case sensitive matching yourself using String.equals() with the returned data although this has some other minor drawbacks such as transmitting the password back to the user (security).
 
Raj Chila
Ranch Hand
Posts: 128
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont think which ever Database it is, you will never get case insensitive results, you will get what you queried for ( that is the minimum contract of a query).

an execute() call returning true does not mean that it has returned some case insensitive results, this means that the query was executed successfully. return instead of what you are doing now, or use executeQuery() and then ResultSet's method to see if there were really any records in the result set. correct me if I am wrong.

I would suggest, use a Query to select count * From ... if it is not too expensive on the applicaiton process.
[ October 25, 2005: Message edited by: RajaniKanth Bhargava ]
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Timothy Sam:


but this would make my query case insensitive... I don't think that is advisable when querying password fields right? I need it to be case sensitive like...

HELLO is not the same as hello...


Woops! Miss-read your post. Sorry. Scott Selikoff is right - you'll need to configure your database to be case sensitive. If that's not an option, you'll have to check that results in you applcaition after they are returned.
 
Anil Kumar Saha
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What will be the solution if the database is DB2?
 
Sabarish Sasidharan
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Anil Kumar Saha:
What will be the solution if the database is DB2?


If database is DB2 UDB, it should be case sensitive by default. To make it case insensitive we use UPPER() when comparing as outlined in the posts above.
 
Sirish Kumar Gongal Reddy
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The solution for your problem is while obtaining the Connection it self you need to select the type of connection i.e it may be a sensitive or insensitive.the code is like this,

DriverManger.registerDriver(Driver name here);
Connection con=DriverManager.getConnection(url here);
Statement stmt=con.createStatement(RESULTSET_TYPE_SENSITIVE OR INSENSITIVE);
ResultSet rs=stmt.executeQuery(your Query here);

Hope that you got my point.If you have any concerns please put a mail then i'll come up with full code.

Thanks & Regards,
G Sirish Reddy.,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic