gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 14:06:06 24 4
gpt4 key购买 nike

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

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)

有什么建议吗?

最佳答案

您有一个名为“类(class)”的数据库吗?或名为类(class)的

据此: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.

关于java - 执行SQL语句时出现语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6194190/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com