Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.cnl.capoi;
- import java.sql.Connection;
- import java.sql.DatabaseMetaData;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- public class CrawlConnection {
- private static final String[] filters = {"^.*DTREE.*$", "^.*DVERS.*$"};
- private static Connection con;
- private static DatabaseMetaData conMeta;
- public static void main(String[] args) throws Exception {
- Class.forName("oracle.jdbc.OracleDriver");
- con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "rmnausr", "opentext");
- conMeta = con.getMetaData();
- crawl();
- con.close();
- }
- private static void crawl() throws Exception {
- ResultSet rsTables = conMeta.getTables(null, null, null, null);
- while (rsTables.next()) {
- String catalog = String.valueOf(rsTables.getObject("TABLE_CAT"));
- String schema = String.valueOf(rsTables.getObject("TABLE_SCHEM"));
- String name = String.valueOf(rsTables.getObject("TABLE_NAME"));
- String type = String.valueOf(rsTables.getObject("TABLE_TYPE"));
- for (String filter : filters) {
- if (name.matches(filter)) {
- System.out.printf("CATALOG: %s, SCHEMA: %S, NAME: %s, TYPE: %s%n",
- catalog, schema, name, type
- );
- }
- }
- }
- rsTables.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment