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?
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.