Java Reference
In-Depth Information
C:> java database.DatabaseMetaDemo
Enhydra InstantDB - Version 3.13
The Initial Developer of the Original Code is Lutris Technologies Inc.
Portions created by Lutris are Copyright (C) 1997-2000 Lutris Technologies, Inc.
We are using InstantDB
Version is Version 3.13
Database default transaction isolation is 0 (TRANSACTION_NONE).
All done!
C:>
Program: SQLRunner
The SQLRunner program is a simple interface to any SQL database for which you have a
JDBC driver and a login name and password. Most databases provide such a program, and
most of them are more powerful. However, this program has the advantage that it works with
any database. The program reads SQL commands from a console window (up to a semi-
colon), passes them to the driver, and prints the results. If the result is a ResultSet , it is prin-
ted using a ResultsDecorator ; otherwise, it is printed as a RowCount .
The abstract ResultsDecorator class ( ResultsFormatter might have been a better name)
is shown in Example 18-12 . A text-mode decorator is used by default; an HTML decorator
(discussed earlier in Example 18-10 ) and an SQL generator (potentially useful in dumping
the data for insertion into another database) is also available. You can specify the decorator
using command-line options or switch using the escape mechanism; for example, a line with
\mh; sets the mode to HTML for the results of all following output.
To avoid hardcoding database parameters, they are fetched from a properties file, which de-
faults to ${user.home}/.db.properties . For example, my .db.properties file contains entries
like the following:
# Connection for the "lhbooks" database
lhbooks.DBDriver=org.postgresql.Driver
lhbooks.DBURL=jdbc:postgresql:ecom
lhbooks.DBUser=thisoneistopsecrettoo
lhbooks.DBPassword=fjkdjsj
# Connection for the "tmclub " database
tmclub.DBDriver=org.postgresql.Driver
tmclub.DBURL=jdbc:postgresql:tmclub_alliston
tmclub.DBUser=dontshowthereaderstherealpassword
tmclub.DBPassword=dlkjklzj
Search WWH ::




Custom Search