Using the API Database
Example 18-4
displays a program, LookupAPI
, that
uses the database built by the MakeAPIDB
program of Example 18-3 and makes interesting
SQL queries against it. LookupAPI
behaves as follows:
When invoked with the name of a class member, it lists the full name (including package and class) of each field and/or method that has that name.
When run with the name of a class, it lists the full name of every class in any package that has that name.
When called with a portion of a package name, it lists the names of all the packages that contain that string.
When invoked with the
-l
option and a class name, it lists every member of every class that has that name.When run with the
-l
option and a portion of a package name, it lists all the classes and interfaces in any package that matches that string.
LookupAPI
reads the
same APIDB.props property file MakeAPIDB
does. Or, alternatively, it reads
a property file specified on the command line following a -p
flag. Using the database connection
parameters in the property file, the program connects to a database
and executes the necessary SQL queries to return the desired
information. Note that it calls the setReadOnly( )
method of the Connection
object. Doing this provides a
hint that the program performs only queries and doesn’t modify the
database in any way. For some database systems, this may improve
efficiency. Other than the setReadOnly(
)
method, this example doesn’t introduce any new JDBC features. It simply ...
Get Java Examples in a Nutshell, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.