I've got a SQL Server 2000 database with a table that has two Foreign Keys.
They are declared as such in the database.
When I use the latest JDBC driver (sp3) to get the MetaData info about these
Foreign Keys, I'm runing into what appears to be a bug. Here's a snippet
code:
ResultSet rsForeignKeys = dbmd.getImportedKeys( null, null, "Recipes" );
while( rsForeignKeys.next() ) {
log.debug( "fktablename: " + rsForeignKeys.getString("FKTABLE_NAME") );
log.debug( "fkcolumname: " + rsForeignKeys.getString("FKCOLUMN_NAME") );
log.debug( "pktablename: " + rsForeignKeys.getString("PKTABLE_NAME") );
log.debug( "pkcolumnename: " + rsForeignKeys.getString("PKCOLUMN_NAME") );
}
This yields the following (with Log4J prefix info ommitted):
fktablename: Recipes
fkcolumname: MenuSectionID
pktablename: MenuSections
pkcolumnename: MenuSectionID
fktablename: Recipes
fkcolumname: MenuSectionID***
pktablename: RecipeType
pkcolumnename: RecipeTypeID
Notice the asterisked item above (asterisks are my own, not code generated).
The MenuSectionID is the fkcolumn name from the first FK entry but it is
show for both fk entries returned by the DBMD object. This is not correct,
the name of the second FK column for this table is "RecipeID". I have
double-checked my relationships in the database and all seems well there.
Any idea what might be going on here?
My thanks,
- Gary
Oh duh.
I just triple-checked by db-definition and found the problem. I had a typo
in the fk definition. The DBMD object was giving me exactly the fk's exactly
as I had (incorrectly) defined them.
Sorry about that.
- Gary
"gaffonso" wrote:
> I've got a SQL Server 2000 database with a table that has two Foreign Keys.
> They are declared as such in the database.
> When I use the latest JDBC driver (sp3) to get the MetaData info about these
> Foreign Keys, I'm runing into what appears to be a bug. Here's a snippet
> code:
> ResultSet rsForeignKeys = dbmd.getImportedKeys( null, null, "Recipes" );
> while( rsForeignKeys.next() ) {
> log.debug( "fktablename: " + rsForeignKeys.getString("FKTABLE_NAME") );
> log.debug( "fkcolumname: " + rsForeignKeys.getString("FKCOLUMN_NAME") );
> log.debug( "pktablename: " + rsForeignKeys.getString("PKTABLE_NAME") );
> log.debug( "pkcolumnename: " + rsForeignKeys.getString("PKCOLUMN_NAME") );
> }
> This yields the following (with Log4J prefix info ommitted):
> fktablename: Recipes
> fkcolumname: MenuSectionID
> pktablename: MenuSections
> pkcolumnename: MenuSectionID
> fktablename: Recipes
> fkcolumname: MenuSectionID***
> pktablename: RecipeType
> pkcolumnename: RecipeTypeID
> Notice the asterisked item above (asterisks are my own, not code generated).
> The MenuSectionID is the fkcolumn name from the first FK entry but it is
> show for both fk entries returned by the DBMD object. This is not correct,
> the name of the second FK column for this table is "RecipeID". I have
> double-checked my relationships in the database and all seems well there.
> Any idea what might be going on here?
> My thanks,
> - Gary
No comments:
Post a Comment