Ignore Letter Case in Search?

i was wondering how id be able to ignore the letter case of names when i searched for contacts. heres my search method:publicvoid searchContacts(String contactName, JPanel searchPanel){

try{

statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);

resultSet = statement.executeQuery("select * from CONTACTS where NAME like '%" + contactName +"%'");

while(resultSet.next()){

searchName = resultSet.getString("NAME");

searchNumber = resultSet.getString("NUMBER");

searchEMail = resultSet.getString("EMAIL");

searchPanel.add(new ContactPanel(searchName, searchNumber, searchEMail));

}

}catch (SQLException ex){

ex.printStackTrace();

}

}

thnx for any help

[1323 byte] By [Alex1989a] at [2007-11-27 11:48:59]
# 1

Normally SQL queries ARE case insensitive aren't they?

So if your CONTACTS table contains 'xyZ' and 'XYz', and you search for 'xyz', it should return both rows.

warnerjaa at 2007-7-29 18:22:30 > top of Java-index,Java Essentials,Java Programming...
# 2

if i type "alex" then i finds no contacts but if i type "Alex" then it comes up with 2. its because its looking for a contactName

Message was edited by:

Alex1989

Alex1989a at 2007-7-29 18:22:30 > top of Java-index,Java Essentials,Java Programming...
# 3

Sorry... editited cos I'm being dense again...

The earlier reply was correct. SQL is generally case insensitive.... at least Microsoft SQL and MySQL are. No experience of others so not sure.

Message was edited by:

c0demonk3y

c0demonk3ya at 2007-7-29 18:22:30 > top of Java-index,Java Essentials,Java Programming...
# 4

i thought sql syntax was case insensitive but values are sensitive?

try (something like) this:

resultSet = statement.executeQuery("select * from CONTACTS where LOWER(NAME) like '%" + contactName.toLowerCase() + "%'");

yorkroada at 2007-7-29 18:22:30 > top of Java-index,Java Essentials,Java Programming...
# 5

> i thought sql syntax was case insensitive but values

> are sensitive?

Not in Microsoft and MySQL... the values are case insensitive as well.

Just doing a like should be sufficient (provided the OP is using MS or MySQL). I don't know about Oracle or PostgreSQL.

c0demonk3ya at 2007-7-29 18:22:30 > top of Java-index,Java Essentials,Java Programming...
# 6

just ran a test in oracle - it's the LIKE clause thats seems to be case sensitive!

select name from case where name LIKE '%secondo%'

returns name il secondo

select name from case where name LIKE '%Secondo%'

returns nothing

yorkroada at 2007-7-29 18:22:31 > top of Java-index,Java Essentials,Java Programming...
# 7

> i thought sql syntax was case insensitive but values

> are sensitive?

>

> try (something like) this:

> > resultSet = statement.executeQuery("select * from

> CONTACTS where LOWER(NAME) like '%" +

> contactName.toLowerCase() + "%'");

>

thnx bud that solved it

Alex1989a at 2007-7-29 18:22:31 > top of Java-index,Java Essentials,Java Programming...