我有下列方法刪除數據庫,但出現語法錯誤,我不知道發生了什麼。執行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)
有什麼建議?
什麼樣的數據庫是您使用? – 2011-05-31 22:15:20
NetBeans中的Java DB。我正在使用德比。 – RandellK02 2011-05-31 22:15:42
您使用的帳戶是否有權刪除數據庫? – BugFinder 2011-05-31 22:16:53