2011-05-31 117 views
2

我有下列方法刪除數據庫,但出現語法錯誤,我不知道發生了什麼。執行SQL語句時出現語法錯誤

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); 
    } 
} 

我打電話與方法:

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

我得到這個錯誤:

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) 

有什麼建議?

+1

什麼樣的數據庫是您使用? – 2011-05-31 22:15:20

+0

NetBeans中的Java DB。我正在使用德比。 – RandellK02 2011-05-31 22:15:42

+0

您使用的帳戶是否有權刪除數據庫? – BugFinder 2011-05-31 22:16:53

回答

10

你有數據庫叫做課程嗎?或命名課程?根據該

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.

+0

我有一個名爲Courses的數據庫。我能夠使用DROP Table命令刪除我的表,這個命令工作正常。 – RandellK02 2011-05-31 22:20:51