Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

tables in the database  RSS feed

 
pranay ahlawat
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to get all the tables/views stored in the database.

(If possible know all the datbases that the driver is serving).
How do I do this.

Which metadata class / any sql query?

Thanks a lot.
 
Makarand Parab
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Check out the DataBaseMetaData interface in the java.sql.package. I think that will solve ur problem. Let me know if u need more help

Regards
Makarand Parab
 
Shailesh Chandra
Ranch Hand
Posts: 1084
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by pranay ahlawat:
any sql query?



On oracle you can exeute query on ALL_OBJECTS
and on sql server I am not sure abouth this but you can check in Information_schema

Shailesh
 
Anand Karia
Ranch Hand
Posts: 156
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi pranay ahlawat

This is only possible if you clearly define which database you are using. Because there are different ways to solve the same in different database.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16043
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi pranay ahlawat

This is only possible if you clearly define which database you are using. Because there are different ways to solve the same in different database.

No, that is not necessary. As Makarand Parab already pointed out, you can do this by looking at the database metadata that you can get by calling the method java.sql.Connection.getMetaData(). Look it up in the API documentation. Class DatabaseMetaData has a method getTables() to get all the tables in the database (that the user with which you logged in into the database has access to).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!