Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getPrimaryKey on Db2

Status
Not open for further replies.

tpass001

Programmer
May 30, 2003
6
US
Hi all,

I am new to Db2 but not to databases.

Here is a snippet of my code
=============
Connection conn = getConnection();
Statement stmt;
stmt = conn.createStatement();
DatabaseMetaData dbmd = conn.getMetaData();
ResultSet rs = dbmd.getPrimaryKeys(null, null, tableName);
cat.debug("b4 rs next"+ rs);
cat.debug("rs next" +rs.next());
cat.debug("pk = + "+ rs.getString("PK_NAME"));
while (rs.next()) {
cat.debug("inside rs next");
String name = rs.getString("TABLE_NAME");
String columnName = rs.getString("COLUMN_NAME");
String keySeq = rs.getString("KEY_SEQ");
String pkName = rs.getString("PK_NAME");
cat.debug("table name : " + name);
cat.debug("column name: " + columnName);
cat.debug("sequence in key: " + keySeq);
cat.debug("primary key name: " + pkName);
cat.debug("");
}
=============================
Here the tableNAme is DSN811A.EMP. So it is the standard employess table and there is a primary key in there called EMPNO.

rs.next() returns false. and i get an exception at trying to get rs.getString("PK_NAME"). If I remove that line then the rs.next loop does not get entered.

According to the documentation I should get the PK_NAME returned and the rest of the information.

Please help me out here.

Thanks for your help.

TP.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top