在这段代码中,我试图在每次运行程序时删除表(如果它们已经存在),但控件不会进入 if
语句。 table1
和 table2
存在于数据库中。我已经在我的数据库中检查过了。由于它不在 if
语句中,当我尝试创建表时,它在最后一行出现以下错误:ORA-00955: name is already used by an existing object
。我做错了什么?
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(" +.....
最佳答案
我会替换这一行
ResultSet rs1 = md.getTables(null, null, "table1",types );
这个
ResultSet rs1 = md.getTables(null, null, "TABLE1",types );
关于java - 名称已被现有对象使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8197599/