The name is already used by an existing object

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(" +.....
+5
source share
2 answers

If the table table1and table2have been created by your program above, their names will be capitalized Oracle. Try

    ResultSet rs1 = md.getTables(null, null, "TABLE1", types);

( table2).

, , , , ..

    statement.executeUpdate("create table \"table1\" (....)");
+5

ResultSet rs1 = md.getTables(null, null, "table1",types );

ResultSet rs1 = md.getTables(null, null, "table1",types );
+6

All Articles