|
|
I have a friend who once had a Metadream.
-
Metadata tells you about the data in a database. It can tell you
about the tables, column names, column types, connections, drivers, and
more. As a matter of fact, there are gobs of methods that you can
use.
-
If you write database tools, or query tools, this can be handy.
-
Say, for example, the Accounting department asks you for report after report.
You write these reports, but start to get bored writing reports all day.
So instead, you give them a query tool where they can easily make their
own query to get data on an as-needed basis.
-
Metadata comes in two flavors:
-
Data about the database.
-
Data about the result set.
-
A special object exists to data about a database, called DatabaseMetaData.
-
Get this object with the getMetaData() method of the Connection class.
-
This tells you a lot about what a database supports. So if you want
to make your program both platform independent and highly optimized, you
can find what the database supports, and then run your program conditionally
on those values.
-
For example, say a union is the best way to write a particular query.
But not all databases support unions. You can use the supportsUnion()
method to see if it supports unions. If so, you can run a union.
If not, you'll have it perform another, perhaps less efficient query.
-
To get data about a ResultSet object, use the ResultSetMetaData
class.
-
Use this to find the name, type, and width of a column in a ResultSet.
-
Use the getMetaData() method of the ResultSet
class.
-
Let's find out a little bit about our database.
Example
|