public void dropTable(String name) {
try {
PreparedStatement stmt = getConnection().prepareStatement("DROP TABLE ?");
stmt.setString(1, name);
stmt.execute();
stmt.close();
} catch (SQLException ex) {
throw new RuntimeException(ex);
}
}```
```dropTable("stats");```
```java.lang.RuntimeException: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''stats'' at line 1```
why am i getting this error?
#drop table not working
1 messages · Page 1 of 1 (latest)
Detected code, here are some useful tools:
<@&987246584574140416> please have a look, thanks.
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
Use regular statement instead of prepared. Preparedstatements do not allow the dropping of tables. Wildcards aren't permitted with preparedstatements as well.
@agile yarrow
A solution to this would be:
public void dropTable(String name) {
try {
Statement stmt = getConnection().createStatement();
stmt.executeUpdate("DROP TABLE " + name);
stmt.close();
} catch (SQLException ex) {
throw new RuntimeException(ex);
}
}
ok thanks
If your question was answered, please type /help-thread close and the thread will close. Have a good day!
Closed the thread.
Closed the thread.