views:

40

answers:

2

I was playing around with the DatabaseMetaData class to see how it works. The java doc comments seem to state one thing, while the code does a different. I know it is an interface, so it is really up to the vendor that supplied the JDBC driver to implement this correctly. But I was wondering if I am missing something or not?

I am using this with a version of Oracle 10g. Basically the comment implies that it will return the following 10 columns in the resultset:

  • TABLE_CAT

  • TABLE_SCHEM

  • TABLE_NAME

  • TABLE_TYPE

  • REMARKS

  • TYPE_CAT

  • TYPE_SCHEM

  • TYPE_NAME

  • SELF_REFERENCING_COL_NAM

  • REF_GENERATION

In reality I only get 5 columns in the result set:

  • TABLE_CAT

  • TABLE_SCHEM

  • TABLE_NAME

  • TABLE_TYPE

  • REMARKS

So what gives? Am I misreading the javadocs or is this pretty much par for the course with jdbc drivers. For instance if I swapped out oracle for MySQL (of course getting the appropriate driver) would I probably get a number of columns?

+1  A: 

JDBC is a spec. Some features are required to conform to the spec; others are optional.

I don't know the complete spec, but this must be one feature that Oracle has chosen not to return all the values expressed in the interface. Other vendors like MySQL may choose to do so.

You'll have to try it and see.

Are the missing columns crucial to your app's operation? It seems like a trivial reason to switch database vendors.

duffymo
@duffymo No I am not missing anything crucial at all, and the columns returned are definitely enough for what I am trying to accomplish. It was more that I was trying to write this particular set of code to be database agnostic. You mentioned a spec, where would one find this, so that you would know what was optional before hand?
jschoen
Also, this is really all for learning purposes, not anything crucial at all. Pure curiosity.
jschoen
You could Google for the spec, but it's expressed in those java.sql interfaces.
duffymo
+3  A: 

The JDBC driver for Oracle 10g that you are using is just fulfilling an older spec. Here is a JavaDoc to which it conforms. You have to know the JDBC version of your JDBC drivers to work with them effectively when you do more than the absolute basics.

Yishai
@Yishai that makes since, thanks for the link.
jschoen