The moose likes JDBC and the fly likes Check Table's Relationships Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Check Table Watch "Check Table New topic

Check Table's Relationships

Joshua Elkino
Ranch Hand

Joined: Jul 24, 2007
Posts: 91
I think this is a simple question, but how do i check which table a foreign key refers to in mysql?

If i use describe tablename then i can see there is a key, but not sure what its refering to. I just want to verify i correctly mapped this in hibernate.

mysql> describe attendedlistent_userent;
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

You can get at this sort of data by querying the database's catalog directly (refer to the MySQL documentation for the appropriate tables) or a better way is to query the DatabaseMetaData (this way your solution is not tied to one database version).

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Joshua Elkino
Ranch Hand

Joined: Jul 24, 2007
Posts: 91
For the interested...

Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3703

Hi Ilya,

That's database specific though, it won't work on all systems. Paul's suggestion of using the JDBC meta data classes is preferable if you're implementing the method as part of a code base. For example, if you need to check from within the application while its running.

My Blog: Down Home Country Coding with Scott Selikoff
Consider Paul's rocket mass heater.
subject: Check Table's Relationships
Similar Threads
Mapping ENUM('0', '1') or CHAR(0) for Boolean
Three problems with mysql...
Hibernate with native SQL issue
need help in JPA ANNOTATION regarding Inheritance.
2 Hibernate Qs: Collections, Annotation Mapping