2

I have the following method that drops the database but I get a syntax error and I dont know what is going on.

public void deleteDB(){
    try{
        Statement s = conn.createStatement();
        System.out.println("Deleteting database...");
        s.execute("DROP DATABASE Courses");
        System.out.println("Database deleted.");
    }
    catch(SQLException error){
        System.err.println("Unable to delete database.");
        error.printStackTrace(System.err);
        System.exit(0);
    }
}

I call the method with:

UpdateDB update = new UpdateDB();
update.connectDatabase(dbName);
update.deleteDB();

I get this error:

java.sql.SQLSyntaxErrorException: Syntax error: Encountered "DATABASE" at line 1, column 6.
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)

Any suggestions?

4
  • 1
    what kind of database are your using? Commented May 31, 2011 at 22:15
  • Java DB in NetBeans. I am using Derby. Commented May 31, 2011 at 22:15
  • Does the account you have used have permission to drop the database? Commented May 31, 2011 at 22:16
  • there does not seem to be a drop database db.apache.org/derby/manuals/reference/sqlj28.html . Maybe you need drop schema? Commented May 31, 2011 at 22:19

1 Answer 1

10

Do you have a database called courses? or a table named courses?

according to this: http://db.apache.org/derby/docs/10.0/manuals/develop/develop13.html

There is no drop database command. To drop a database, delete the database directory with operating system commands.

Sign up to request clarification or add additional context in comments.

1 Comment

I have a database named Courses. I was able to delete my table using a DROP Table command that worked fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.