
在Java代码中判断数据库中某张表是否存在:
1、使用JdbcTemplate bean
public boolean validateTableNameExist(String tableName) {
int tableNum = jdbcTemplate.queryForInt("SELECT COUNT(*) FROM ALL_TABLES WHERE TABLE_NAME=" + tableName);
if (tableNum > 0) {
return true;
}else {
return false;
}
}2、使用Connection对象
public boolean validateTableNameExist(String tableName) {
Connection con = getYourCnnection;
ResultSet rs = con.getMetaData().getTables(null, null, tableName, null);
if (rs.next()) {
return true;
}else {
return false;
}
}注:
立即学习“Java免费学习笔记(深入)”;
1、检查某表中是否存在某个字段,注意大写
select count(*) from User_Tab_Columns where table_name='TABLENAME' and column_name='COLUMNNAME';
2、检查某数据库内,是否存在某张表,注意表名要大写
select count(*) from all_tables where table_name='TABLENAME';











