Microsoft Accessデータベースを終了する場合は、テーブルを削除する必要があるアプリケーションが1つあります。 コードhereを見ました。削除したいテーブル名はdata_tableであり、アクセスデータベースファイル名はlocal_entry ですので、アプリケーションのためにコードを変更する必要があります。Microsoft Accessにテーブルが存在する場合は
String dropTable = "DROP TABLE ";
String[] tables = DB_TABLE;
は、私は2番目のラインについて data_table、何にのDROP TABLEを変更することができます。
public void testDropTable() throws SQLException{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:MsAccessDSN");
Statement stmt = con.createStatement();
ResultSet checkTable = con.getMetaData().getTables(null, null, "POI", null);
String tableName = null;
while (checkTable.next())
{
System.out.println("In here");
tableName = checkTable.getString("TABLE_NAME");
System.out.println(tableName);
}
if (tableName != null){
try {
String dropTable = "DROP TABLE ";
String[] tables = DB_TABLE;
for (int i = 0; i < tables.length; i++){
String stringCode = new String();
stringCode = stringCode + tables[i];
System.out.println(dropTable + tables[i]);
// Drop each table in the array.
int temp = stmt.executeUpdate(dropTable + tables[i]);
}
}
catch (Exception e) {
System.err.println("Exception in testDropTable(): \n"
+ "Drop Table testDropTable threw an exception: " +(e.getMessage()));
}
}
else{
con.close();
}
}
私は、私はこの2行を変更する必要があると思います。私はこの方法で全体のコードを変更しますが、問題まであり、このDB_Tableの 何ですか:
public void testDropTable() throws SQLException{
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
}
Connection con = DriverManager.getConnection("jdbc:odbc:MsAccessDSN");
Statement stmt = con.createStatement();
ResultSet checkTable = con.getMetaData().getTables(null, null, "POI", null);
String tableName = null;
while (checkTable.next())
{
System.out.println("In here");
tableName = checkTable.getString("data_table");
System.out.println(tableName);
}
if (tableName != null){
try {
String dropTable = "DROP TABLE ";
String[] tables = {"data_table"};
for (int i = 0; i < tables.length; i++){
String stringCode = new String();
stringCode = stringCode + tables[i];
System.out.println(dropTable + tables[i]);
// Drop each table in the array.
int temp = stmt.executeUpdate(dropTable + tables[i]);
}
}
catch (Exception e) {
System.err.println("Exception in testDropTable(): \n"
+ "Drop Table testDropTable threw an exception: " +(e.getMessage()));
}
}
else{
con.close();
}
}
おかげで... まさにこのコードの仕事。 あなたの質問が好きなら、私の質問をアップグレードしてください。 –
@shrishなぜOPの質問からそのコードブロック全体を削除しましたか? vinitvikashは不要なコードブロックですか? – gideon
@gideon OPが正しいかどうかを確認するために変更されたコードの行だけです。私はこの質問が自明だと思います。 – Shirish11