嗨我在我的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();
}
答案 0 :(得分:2)
感谢MadProgrammer和其他人,实际上我很想把提交声明放在我的代码上..
Statement stmt = conn.createStatement();
String sqlCommand = "DROP TABLE IF EXISTS 'myDatabase.myTable' ";
System.out.println("output : " + stmt.executeUpdate(sqlCommand));
stmt.close();
conn.commit(); // commit after execute sql command
//COMMIT TRANSACTION makes all data modifications performed since
//the start of the transaction a permanent part of the database,
conn.close();