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

 
 


Clark
Sun's JDBC-ODBC driver does not implement the getPrimaryKeys() method for the DatabaseMetaData Objects.
1 Answer(s)      2 years and 7 months ago
Posted in : JDBC

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 Pages:

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.