In this code, I try to delete tables if they already exist every time I run the program, but the control is not part of the statements if. table1and table2are present in the database. I checked this in my database. Because it is not part of the operators if, it gives the following error on the last line, when I'm trying to create the table: ORA-00955: name is already used by an existing object. What am I doing wrong?
Statement statement = connection.createStatement();
DatabaseMetaData md = connection.getMetaData();
String[] types = {"TABLE"};
ResultSet rs1 = md.getTables(null, null, "table1",types );
if (rs1.next()) {
System.out.println(rs1.getString(3));
statement.executeUpdate("drop table table1");
}
rs1.close();
ResultSet rs2 = md.getTables(null, null, "table2", types);
if (rs2.next()) {
statement.executeUpdate("drop table table2");
}
rs2.close();
statement.executeUpdate("create table table1(" +.....
source
share