在Java代码中判断数据库中某张表是否存在:
1、使用JdbcTemplate beanpublic 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;
}
}
注:
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';
更多java知识请关注java基础教程。