我有一个嵌入了数据库的桌面应用程序。当我执行我的程序时,我需要检查特定表是否存在,如果不存在则创建它。
如果我的数据库有一个名为 conn 的 Connection 对象,我该如何检查呢?
最佳答案
DatabaseMetaData dbm = con.getMetaData();
// check if "employee" table is there
ResultSet tables = dbm.getTables(null, null, "employee", null);
if (tables.next()) {
// Table exists
}
else {
// Table does not exist
}
关于java - 检查表是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2942788/