View Primary Keys

View Primary Keys

Post by bmarq.. » Thu, 13 Apr 2000 04:00:00



Hi all,

I am trying to get the primary keys from a VIEW use the
DataBaseMetaData.
So I tried :
DatabaseMetaData aDBMD  = theConnection.getMetaData();
ResultSet aResultSet = aDBMD.getPrimaryKeys("","",aTableName);
while (aResultSet.next()) {
aColumnName     = aResultSet.getString(4);
System.out.println(aColumnName);

Quote:}

But the ResultSet is Empty. (and I am sure to have a primary key...)
This code works very well when I try to get the primary keys from a
TABLE...

So can u help me?

thanks
bye

Bruno

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

View Primary Keys

Post by Markus Lau » Thu, 13 Apr 2000 04:00:00


Bad Luck here. What databases actualy give you on meta-data can be
inconsistent. Some DB's just don'tgive you the primarys, others do.

An alternative query of the the meta data is the following: But remember
DB's don't always give you what you expect.

ResultSet keys =
dbmd.getIndexInfo(con.getCatalog(),"%",table,uniqueOnly,false);

Have fun. (I've had my share of cursing this topic)


> Hi all,

> I am trying to get the primary keys from a VIEW use the
> DataBaseMetaData.
> So I tried :
> DatabaseMetaData aDBMD  = theConnection.getMetaData();
> ResultSet aResultSet = aDBMD.getPrimaryKeys("","",aTableName);
> while (aResultSet.next()) {
> aColumnName     = aResultSet.getString(4);
> System.out.println(aColumnName);
> }

> But the ResultSet is Empty. (and I am sure to have a primary key...)
> This code works very well when I try to get the primary keys from a
> TABLE...

> So can u help me?

> thanks
> bye

> Bruno

> Sent via Deja.com http://www.deja.com/
> Before you buy.