【发布时间】:2014-09-23 01:18:09
【问题描述】:
嗨,我已经在我的 sqlite 数据库上尝试过这个命令,但它不会删除/删除我的数据库表, 这是我的reference
Statement stmt = conn.createStatement();
String sqlCommand = "DROP TABLE 'myTable' ";
System.out.println("output : " + stmt.executeUpdate(sqlCommand));
//Output
output : 0
没有返回错误,所以我仍然无法自己弄清楚是什么导致代码无法正常工作。
删除表的代码
Connection c = null;
Statement stmt = null;
String sql;
c = openSqlite(c); //method i create to setup sqlite database connection
stmt = c.createStatement();
try{
System.out.println("Deleting table in given database...");
String sqlCommand = "DROP TABLE 'myTable' ";
stmt.executeUpdate(sqlCommand);
System.out.println("Table deleted in given database...");
stmt.close();
c.commit();
c.close();
}catch(SQLException se){
//Handle errors for JDBC
se.printStackTrace();
}
【问题讨论】:
-
您是否检查过数据库以查看该表是否实际上已被删除?因为
executeUpdate可能会返回“(1) SQL 数据操作语言 (DML) 语句的行数或 (2) 0 用于不返回任何内容的 SQL 语句” -
是的,我已经多次刷新我的表格,但表格及其内容仍然存在..
-
在命令行中使用“DROP TABLE IF EXISTS 'myDatabase.myTable”并检查会发生什么
-
另外,请确保您启用自动提交或提交事务...
-
表名真的是“
myDatabase.myTable”吗?使用引号,myDatabase.是表名的一部分。