简体   繁体   English

执行 SQL 语句时出现语法错误

[英]Getting a syntax error when executing SQL statement

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根据这个: 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.要删除数据库,请使用操作系统命令删除数据库目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM