`

查询数据库是否存在某表

阅读更多
/**
     * 查询数据库是否有某表
     * @param cnn
     * @param tableName
     * @return
     * @throws Exception
     */ 
    @SuppressWarnings("unchecked") 
    public boolean getAllTableName(String tableName) throws Exception { 
        Connection conn = jdbcTemplate.getDataSource().getConnection(); 
        ResultSet tabs = null; 
        try { 
            DatabaseMetaData dbMetaData = conn.getMetaData(); 
            String[]   types   =   { "TABLE" }; 
            tabs = dbMetaData.getTables(null, null, tableName, types); 
            if (tabs.next()) { 
                return true; 
            } 
        } catch (Exception e) { 
            e.printStackTrace(); 
        }finally{ 
            tabs.close(); 
            conn.close(); 
        } 
        return false; 
    }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics