Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the column name of the primary key of a Database Table from the ResultSet or ResultSetMetaData object in JAVA?

I am writing a Java Application. I have got a ResultSet. Now I want to find out the coloumn name of the primary key of the table.

Is it possible to get that coloumn name through ResultSet object or ResultSetMetaData Object or any other way.

I didn't find any way to find this.

like image 810
Yatendra Avatar asked Feb 03 '23 06:02

Yatendra


1 Answers

No. You will not get that information from ResultSet or ResultSetMetadata.

What you want to use for that is DatabaseMetadata class. From that class check getPrimaryKeys method to get the information you want.

Of course, to use this, you will need to know the name of the table.

like image 176
Pablo Santa Cruz Avatar answered Feb 05 '23 21:02

Pablo Santa Cruz