I am trying to search my database using mySQL through JDBC. When I use this statement:
SELECT * FROM tablename WHERE name='joe';
It does a case insensitive search and returns any rows that have ‘Joe’ or ‘joe’, which is what I want. I ran select collation(version()), and this returned ‘utf8_general_ci’, which is apparently supposed to be case insensitive. However, when I run the same query using JDBC within my Java applet, it does a case sensitive search. Here is my query2 function:
try {
Vector<Vector<String>> out = new Vector<Vector<String>>() ;
Connection con = connect() ;
Statement statement = con.createStatement() ;
System.out.println( "SQL: " + s ) ;
ResultSet rs = statement.executeQuery(s) ;
while( rs.next() )
{
String r = rs.getString(1) ; // RS is indexed from 1
Vector<String> q = new Vector<String>() ;
for( int i = 2 ; i <= tableSize ; i ++ )
{
q.add(r) ;
r = rs.getString(i) ;
}
q.add(r) ;
out.add(q) ;
}
con.close() ;
return( out ) ;
} catch (SQLException e) {
System.err.println( "SQL EXCEPTION" ) ;
System.err.println( s ) ;
e.printStackTrace();
}
And here is my select function that calls query2:
public static Vector<Vector<String>> select( String table , List<String> columns , List<String> values )
{
String statement = "SELECT * from `" + table + "` WHERE " ;
for( int i = 0 ; i < columns.size(); i ++ )
{
statement += columns.get(i) + "='" + values.get(i) + "'" ;
if( i + 1 < columns.size() )
statement += " AND " ;
}
statement += " ;" ;
return query2 ( statement , tableSize(table) ) ;
}
Any idea how I can make this query case insensitive?
It turns out that the search I thought was using the
selectfunction was actually using a different function. This function was selecting everything from the database and sorting through it client-side. I tested theselectfunction and it actually is case insensitive, without having to use any of the tips given (but thanks for the advice!).