This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi all! Does anyone know if is there a method by which, given a jdbc url and driver, the system would returns me the list of tables available for that database? Example for MSSQLServer: Driver: "com.microsoft.jdbc.sqlserver.SQLServerDriver" url:"jdbc:microsoft:sqlserver://localhost:1433;databaseName=myweb" I have a list of tables here. How could I get such a list? I have already tried with getCatalogs() and getTables() methods of DatabaseMetaData interface. Thanks
Yep, it should work unless not supported by the driver you are using. But you have the option to query the catalog table yourself and get a ResultSet just like getTables() would give you. The catch is you loose portability...
"Worthy", The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp. We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please edit your profile and select a new name which meets the requirements. Thanks. Dave
Joined: Jul 24, 2002
Thanks to all! Actually the getMethods() method worked but it was requireing a catalog as parameter. So, first I should get a list of catalog by means of getCatalogs() method, and then pass the catalog name I am interested in to the getTables() method. I tried and it worked. Thanks to everybody anyway(I changed my nick name as suggested by the web master). Marco.
Marco, you can use null in place of catalog/schema parameters to return all tables regardless of catalog/schema Might save you a few steps if you can just ignore these. Jamie
Joined: Jul 24, 2002
Originally posted by Jamie Robertson: Marco, you can use null in place of catalog/schema parameters to return all tables regardless of catalog/schema Might save you a few steps if you can just ignore these. Jamie
Yes, but i needed to extract only the tables belonging to a specific catalog, so passing the catalog to the getTables() method worked fine. Thank You for Your reply.