Microsoft Access 데이터베이스를 종료하면 테이블을 삭제해야하는 애플리케이션이 하나 있습니다. 코드 here을 보았습니다. 삭제할 테이블 이름은 이고 데이터 테이블은이고 액세스 데이터베이스 파일 이름은 입니다. local_entry 그래서 코드를 변경해야 응용 프로그램에서 작동합니다.Microsoft Access에 테이블이 존재하면 삭제
String dropTable = "DROP TABLE ";
String[] tables = DB_TABLE;
내가 DROP 표 data_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();
}
}
는 나는이 두 라인을 변경할 필요가 있다고 생각합니다. 나는이 방법으로 전체 코드를 변경하지만 문제까지가이 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