【问题标题】:Getting a syntax error when executing SQL statement执行 SQL 语句时出现语法错误
【发布时间】:2011-05-31 22:13:09
【问题描述】:

我有以下删除数据库的方法,但出现语法错误,我不知道发生了什么。

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)

有什么建议吗?

【问题讨论】:

  • 你用的是什么数据库?
  • NetBeans 中的 Java DB。我正在使用德比。
  • 您使用的账号是否有删除数据库的权限?
  • 似乎没有 drop database db.apache.org/derby/manuals/reference/sqlj28.html 。也许你需要drop schema

标签: java sql embedded-database


【解决方案1】:

你有一个名为课程的数据库吗?还是一个名为table的课程?

据此:http://db.apache.org/derby/docs/10.0/manuals/develop/develop13.html

没有删除数据库命令。要删除数据库,请使用操作系统命令删除数据库目录。

【讨论】:

  • 我有一个名为 Courses 的数据库。我能够使用运行良好的 DROP Table 命令删除我的表。
猜你喜欢
  • 1970-01-01
  • 2013-10-07
  • 2014-12-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-21
相关资源
最近更新 更多