#drop table not working

1 messages · Page 1 of 1 (latest)

agile yarrow
#
    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?
brittle turretBOT
#

<@&987246584574140416> please have a look, thanks.

brittle turretBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

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.

digital atlas
#

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);
    }
}
agile yarrow
#

ok thanks

digital atlas
# agile yarrow ok thanks

If your question was answered, please type /help-thread close and the thread will close. Have a good day!

brittle turretBOT
#

Closed the thread.

brittle turretBOT
#

Closed the thread.