1.

Is There A Way To Find The Primary Key(s) For An Access Database Table? Sun's Jdbc-odbc Driver Does Not Implement The Getprimarykeys() Method For The Databasemetadata Objects?

Answer»

Answer : // Use meta.getIndexInfo() will
//GET you the PK INDEX. Once
// you know the index, retrieve its column name
DatabaseMetaData meta = con.getMetaData();
String key_colname = NULL;
// get the PRIMARY key information
rset = meta.getIndexInfo(null,null, table_name, TRUE,true);
while( rset.next())
{
String idx = rset.getString(6);
if( idx != null)
{
//Note: index "PrimaryKey" is Access DB specific
// other db server has diff. index syntax.
if( idx.equalsIgnoreCase("PrimaryKey"))
{
key_colname = rset.getString(9);
setPrimaryKey( key_colname );
}
}
}



Discussion

No Comment Found