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
why won't DatabaseMetaData.getTables() work for you? Are you getting an exception? Are you getting no results back?
Paulo Salgado
Ranch Hand
Joined: Jan 18, 2002
Posts: 98
posted
0
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
alzamabar
Ranch Hand
Joined: Jul 24, 2002
Posts: 379
posted
0
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
alzamabar
Ranch Hand
Joined: Jul 24, 2002
Posts: 379
posted
0
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.
Balaji Loganathan
author and deputy
Bartender
Joined: Jul 13, 2001
Posts: 3150
posted
0
Originally posted by Marco Tedone:
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.
Would you be interested in posting the code snippet here. ?? if so, please.Actaully i tried the same but it only returns 1 table name out of 10