-1

I need to find candidate keys of a table. As for a column to be a candidate key, it must be (1) NOT NULL and (2) UNIQUE. So what I am doing is:

   for(i=1;i<colcount; i++){
       if( (resultset.getmetadata().isnullable(i)==0) && (UNIQUE_COND) ){
            // IS A CANDIDATE KEY
       }
   }

How can I check for UNIQUE condition? I am using mysql db through JDBC. Is there another way to get candidate keys? Thanks.

1 Answers1

0

You need to use the DatabaseMetaData, not the metadata of the resultset. Specifically you need to look at:

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197