I am developing a two-tier java application that basically displays mySQL database results in a JTable in a GUI. The mySQL queries are typed in by the user in a textArea and then an ‘execute command’ button is pressed and the mySQL results corresponding to that command simply appear in the JTable.
The problem I am running into is when I try to type in a query such as “SELECT * FROM bikes WHERE COST=10000;” everything works as expected and results are returned. However, if I type in “select * from bikes where cost=10000;”, no results are returned and basically nothing happens, not even getting an error. I tried running ‘toUpperCase()’ on the query, which didn’t fix the problem.
I was wondering what might be causing this problem? I am aware that mySQL is not case sensitive, so it should work even if my SELECT is lower case…
The code below is a snippet of the area that might be causing the problem.
public void setQuery(String query) throws SQLException, IllegalStateException{
if(!connectedToDatabase)
throw new IllegalStateException("Not Connected to Database");
String firstWord = query.substring(0, 6);
if(firstWord.toUpperCase().equals("SELECT")){
resultSet = statement.executeQuery(query);
}
else if(firstWord.toUpperCase().equals("INSERT") || firstWord.toUpperCase().equals("DELETE") || firstWord.toUpperCase().equals("UPDATE")){
statement2.executeUpdate(query);
}
metaData = resultSet.getMetaData();
resultSet.last();
numberOfRows = resultSet.getRow();
fireTableStructureChanged();
}
equals.ifblock, try adding some logging into that block.