繁体   English   中英

在Java中,如何删除Sqlite表

[英]In Java, How to Drop Sqlite Table

嗨,我已经在我的sqlite数据库上尝试过此命令,但是它不会删除/删除我的数据库表,这里是我的参考

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();
}

感谢MadProgrammer等,实际上我想念将commit语句放在我的代码上。

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();

暂无
暂无

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

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