my dog learned polymorphism*
The moose likes JDBC and the fly likes DatabaseMetaData.getExportedKeys() returns empty ResultSet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "DatabaseMetaData.getExportedKeys() returns empty ResultSet" Watch "DatabaseMetaData.getExportedKeys() returns empty ResultSet" New topic
Author

DatabaseMetaData.getExportedKeys() returns empty ResultSet

Alex Feng Lau
Greenhorn

Joined: Nov 20, 2010
Posts: 3
I'm trying to dynamically get the parent table names and foreign key column names of a database. However, when I try to use getExportedKeys() it returns an empty ResultSet.

I have read on another thread that this may be a known bug. The thread recommends upgrading the mysql connector to the latest version. I have upgraded to the latest alpha mysql-connector-java-6.0-nightly-20101119-bin.jar for Mac OS X but the issue still remains.

http://www.tonews.com/thread/1395546/mailing/database/mysqljava/databasemetadata_getexportedkeys.html

I have created a simple table using a .sql script. I am using MySQL.


I am using the following to extract the results from the database.


I am able to retrieve primary keys calling getPrimaryKeys() just fine. However, calling getExportedKeys() always returns a ResultSet that is empty. What might I be doing incorrectly? Thank you for reading this!


Thousands of candles can be lighted from a single candle, and the life of the candle will not be shortened. Happiness never decreases by being shared.
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3697
    
    5

Are you sure the MySQL driver supports this? Not all databases support advanced driver features. For example, the ResultSet method getGeneratedKeys() is only support by some drivers. Alternatively, some databases, MySQL I believe is one of them, maintains a set of "system database tables" about "user database tables". You can often query them for the information you need, but they are usually quite database specific in structure.


My Blog: Down Home Country Coding with Scott Selikoff
Alex Feng Lau
Greenhorn

Joined: Nov 20, 2010
Posts: 3
I tried downloading and importing the latest driver, but I do not know if it supports getExportedKeys().

mysql-connector-java-6.0-nightly-20101119-bin.jar

An example here shows hints that it should work for MySQL databases though.
http://www.java2s.com/Code/Java/Database-SQL-JDBC/GetForeignKeys.htm

I also tried this query, but it didn't return any results. I'm assuming pdb is the database name and ptable is the table name. I found this from http://www.artfulsoftware.com/infotree/mysqlquerytree.php

Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3697
    
    5

The example uses Oracle though. I suspect if its not returning any results, the driver does not support it. There's often many features JDBC drivers neglect to support.
Alex Feng Lau
Greenhorn

Joined: Nov 20, 2010
Posts: 3
I believe you are right, this is probably a driver issue. I will try to use Oracle and see how that goes. Thank you for all your help Scott!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DatabaseMetaData.getExportedKeys() returns empty ResultSet
 
Similar Threads
Composite Foreign Key that maps to Unique Constraint
ORM and Antipatterns
Problems with .sql(script files) and .properties files. [Using Netbeans]
getting info about primary and foreign keys
cascading classes and tables (how to update ?)