简体   繁体   中英

How to get VIEW references (base tables) through JDBC?

When I create VIEW, database engine pases my query and store it some how. Can I then find out what tables are used by one view? I understand that different databases may be differently. May have some sort of level of abstraction throw JDBC.

Something tells me that this is done through getTables(?):

Connection con = DriverManager.getConnection(DBURL, DBUSER, DBPASS);        
DatabaseMetaData md = con.getMetaData();
md.getTables(null, null, null, null);

If it can not be. Are there solution in particular for Oracle database (like view/referenses in plsql developer)?

Oracle:

Select * from dictionary 

Returns many system tables/functions you have access to which contain valuable structure information.

in that list you will see

Select * from ALL_Views (which contains the source SQL for the view) which could be parsed for table names.

Though I think there's an all_Dependencies or all_References view that will contain required references to tables in seperate fields which would be easier to parse I'm looking for that now...

Select * from All_dependencies WHERE Name = 'YOUR_VIEWNAME' and Referenced_Type='TABLE' will return all referenced tables.

Though I'm not sure how those features work with Linked tables. so if you're referencing external tables though a linked server... those features may not work.

EDIT : Nevermind, misread the question: I thought you wanted to retrieve the views themselves.

As far as I know there is no JDBC specific way to retrieve this information: you will need to dive into your database specific system tables and see if that information is available.

Answer below specifies how to retrieves view and does not answer the question:

DatabaseMetaData#getTables() with type "VIEW"

eg

dmd.getTables(catalog, schema, "%", new String[] {"VIEW"});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM