Question

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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top