DatabaseMetaData dbm = connection.getMetaData(); // connection is of type Connection (in JDBC)
ResultSet tables = dbm.getTables(null, null, "table name", null); // check if table is there
if (tables.next()) {
//Table exists
} else {
//Table does not exist
}
我的问题是如何检查 View 是否存在。上面的代码是如何检查表是否存在。我知道它与上面的代码类似,但我遇到了麻烦。
最佳答案
getTables()
方法可以返回所有类型的表(其中 View 被视为表的一种类型)。最后一个参数可用于搜索特定类型。
在您的情况下,您可以使用dbm.getTables(null, null, "viewname", new String[]{"VIEW"});
。 javadocs对此进行了很好的解释,因此您应该在在这里提问之前先阅读它们。
关于java - java中如何检查 View 是否存在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34416544/