This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes getTables in DatabaseMetadata not giving proper results Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "getTables in DatabaseMetadata not giving proper results" Watch "getTables in DatabaseMetadata not giving proper results" New topic
Author

getTables in DatabaseMetadata not giving proper results

Amrit Tiwana
Greenhorn

Joined: Jun 03, 2004
Posts: 24
Hi,

I'm using following code to get all tables types with name 'Addresses' by using getTables in DatabaseMetadata, but i m not getting proper results.

ResultSet rs1 = dbm.getTables("MYDB",null,"Addresses", null);

while(rs1.next()) {
String sch = rs1.getString("TABLE_SCHEM");
String table = rs1.getString("TABLE_NAME");
System.out.println("Name =" + table);
System.out.println("Schema =" + sch);
}

In MYDB database, I'm having three users 'dbo', 'alldata', 'user1'. My actual 'Addresses' table is in alldata and having views with name 'Addresses' in dbo and user1. Users 'alldata', 'user1' has no login names but user 'dbo' has login name 'sa'.

The above code just print:
Name = Addesses
Schema = dbo

but if I rename the view 'Adresses'in dbo i get:
Name = Addresses
Schema = alldata
Name = Addresses
Schema = user1

but if I change the line 2 in above code as:
ResultSet rs1 = dbm.getTables("MYDB","alldata","Addresses", null);

I get following output:
Name = Addresses
Schema = alldata

I just want to know why the code snipett above doesn't geive me required output i.e.
Name = Addesses
Schema = dbo
Name = Addresses
Schema = alldata
Name = Addresses
Schema = user1
David Ulicny
Ranch Hand

Joined: Aug 04, 2004
Posts: 724
I think this features depends on driver which you are using. Better way is to use system catalogs to obtain database objects itself. For MSSQL look into the master database in system tables. There are also system stored procedures which helps you with system tables.


SCJP<br />SCWCD <br />ICSD(286)<br />MCP 70-216
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getTables in DatabaseMetadata not giving proper results
 
Similar Threads
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state
Can't declare a Sybase Cursor for StoredProcedures using Spring
segregating Table Synonyms with View Synonyms
problem while reading data from excel sheet
Review of my first Session EJB bean for best practice