• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DatabaseMetaData.getExportedKeys() returns empty ResultSet

 
Alex Feng Lau
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Scott Selikoff
author
Saloon Keeper
Posts: 4020
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Alex Feng Lau
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author
Saloon Keeper
Posts: 4020
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic