Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JDBC Metada retrieve Constraint information

I need information about table and column name from the name of the constraint.

exists someone similar to connection.getMetadata().getX to retrieve the constraint information?

my test case is in Oracle Database, but my best solution I just want to solve with jdbc

like image 215
jrey Avatar asked Jul 15 '12 18:07

jrey


1 Answers

If you are talking about foreign key and primary key constraints. The DatabaseMetaData does provide methods for retrieving this information: you can use getImportedKeys(..) and getCrossReference(..) for foreign keys, and getPrimaryKeys(..) and getExportedKeys(..) for primary keys.

Just be careful how you use them: getCrossReference(..) and getExportedKeys are a bit counter-intuitive in my opinion.

If you also need unique constraints, then you should be able to use getIndexInfo(..) with passing true for the parameter unique.

like image 69
Mark Rotteveel Avatar answered Oct 09 '22 17:10

Mark Rotteveel