Sun's JDBC-ODBC driver does not implement the getPrimaryKeys() method for the DatabaseMetaData Objects.

Sun's JDBC-ODBC driver does not implement the getPrimaryKeys() method for the DatabaseMetaData Objects.

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.

View Answers

November 15, 2010 at 4:26 PM

Hi friends,

// 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 );
}

} .

Thanks.









Related Tutorials/Questions & Answers:

Ads