Desktop application querying problem from panel
I have a simple desktop application and also i have class name baseClass. When i run the program, a frame is occured and i set an event handler for a button. When this button clicked i call a function from baseClass and send a table name as a parameter to this function. And this function executes a sql statement. I have a problem with this sql query. It throws exception like "You have an error with SQL syntax etc..." But i think there is not.
statement.executeQuery("SELECT * FROM '"+tableName+"'");
statement.executeQuery("SELECT * FROM gamesonstore");
My table name is gamesonstore. First line throws exception but second line works. I checked if problem is occured because of overridable method call from constructor or not. But in this case i supposed second line throws exception also but it doesnt. So what is the problem with this ? My exception is:
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''gamesonstore'' at line 1"
Re: Desktop application querying problem from panel
Quote:
"You have an error with SQL syntax etc..." But i think there is not.
When there is a difference of opinion like this the database and Java runtime win.
Perhaps you could take a look at the expression that is invalid:
Code:
System.out.println("About to execute: " + "SELECT * FROM '"+tableName+"'");
statement.executeQuery("SELECT * FROM '"+tableName+"'");
What happens when you type that command directly into a database client?
Re: Desktop application querying problem from panel
I used similar almost same expression but there is not exception. They are working.
Re: Desktop application querying problem from panel
I don't understand.
Did you add the line I suggested? What output did it produce? What does that output yield when you enter the command directly into the mysql client? How did the output from that line differ from that which you used in the other executeQuery() (the one that did not throw the exception)?
[Edit] Or have a read of http://dev.mysql.com/doc/refman/5.0/en/identifiers.html