Reputation: 7
I keep getting this error when trying to connect to the database.
This is my prepared statement
String SQL = "SELECT * FROM `?` WHERE `HomeTeam` = '?'";
PreparedStatement prepst;
prepst = con.prepareStatement(SQL);
prepst.setString(1,box1.getSelectedItem().toString());
prepst.setString(2,box1.getSelectedItem().toString());
rs = prepst.executeQuery();
Anyone know why I get this error?
Upvotes: 0
Views: 5181
Reputation: 20073
Use
String SQL = "SELECT * FROM ? WHERE HomeTeam = ?";
Don't use ` to nest parameters, use ' to nest values you're comparing against if you're hard coding them.
You can't use ? to specify a table name.
Upvotes: 0
Reputation: 115398
I think that your problem is in '
and ``` symbols. You should fix the sql as follwing:
String SQL = "SELECT * FROM ? WHERE HomeTeam = ?";
However I am not sure that parameter placeholder ?
is supported after from
. So, propbably you will have to put it yourself, e.g.:
String table = box1.getSelectedItem().toString();
String SQL = "SELECT * FROM " + table + " WHERE HomeTeam = ?";
Upvotes: 1