Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

Get all primary keys in database.

Thread view: 
tolu45 - 01 Dec 2005 14:27 GMT
Hi, I am writing a code to retrieve all the primary keys of the tables
in the database. I tried to use
DatabaseMetadata dbmd = dbConnection.getMetaData();
ResultSet rs = dbmd.getprimarykeys(null,null ,"%"),

I do not get the result set in my vector which i created to store the
primarykeys. But when i explicitly write the name of the table like
ResultSet rs = dbmd.getprimarykeys(null,null, "movies"), i get the
primary key. DO someone know why i have this problem?
Michael Rauscher - 01 Dec 2005 16:27 GMT
tolu45 schrieb:
> Hi, I am writing a code to retrieve all the primary keys of the tables
> in the database. I tried to use
[quoted text clipped - 5 lines]
> ResultSet rs = dbmd.getprimarykeys(null,null, "movies"), i get the
> primary key. DO someone know why i have this problem?

Yep, you don't have a table named "%".

Bye
Michael
EricF - 02 Dec 2005 05:36 GMT
>tolu45 schrieb:
>> Hi, I am writing a code to retrieve all the primary keys of the tables
[quoted text clipped - 11 lines]
>Bye
>Michael

Michael is right. The JDBC implemetation is building a select statement to
query the DB catalog. '%' is only used as a wild card when used with a LIKE
clause. (There may be some implementations where % would work - but I'd be
surprised.)

Eric
Lee Fesperman - 02 Dec 2005 10:11 GMT
> >tolu45 schrieb:
> >> Hi, I am writing a code to retrieve all the primary keys of the tables
[quoted text clipped - 16 lines]
> clause. (There may be some implementations where % would work - but I'd be
> surprised.)

Actually, certain methods in java.sql.DatabaseMetaData will accept one or more arguments
containing wildcards (LIKE pattern), such as, getTables(). See the docs. However,
getPrimaryKeys() does not, which was Michael's point.

To the OP: the solution is to use getTables() to get a set of tables and then invoke
getPrimaryKeys() on each table from that set.

Signature

Lee Fesperman, FFE Software, Inc. (http://www.firstsql.com)
==============================================================
* The Ultimate DBMS is here!
* FirstSQL/J Object/Relational DBMS  (http://www.firstsql.com)



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.