
Create a JDBC Table Model #24
Chapter 3, Tables and Trees
|
127
HACK
With the queries done, you just convert the ArrayLists to real arrays (which
offer quick lookups for the get methods). The implementations of the
AbstractTableModel
methods mentioned previously, as well as the improved
implementations of
getColumnClass( )
and
getColumnName( )
, are trivial uses
of the
columnNames
,
columnClasses
, and
contents
arrays built up by this
method.
Testing Things Out
Before you say “I can’t run this hack, I don’t have a database,” relax! The
open source world has you covered. And no, it’s not some big thing like
JBoss. HSQLDB, more commonly known by its old name, Hypersonic, is a
JDBC relational database engine written in Java. It is really small and can be
run as a standalone server or within your JVM. If you are database-less, grab
HSQLDB from http://hsqldb.sourceforge.net/.
Whatever your database, you’ll need a driver classname, URL, username,
and password to make a connection to the database. If you have your own
database, I trust you already know this. If you just downloaded HSQLDB
one paragraph ago, then you’ll be using the following information:
• Driver: org.hsqldb.jdbcDriver
• URL: jdbc:hsqldb:file:testdb
• User: sa
• Password: (none)
This assumes you’ll be running Hypersonic as part of your application,
meaning you’ll need to extend your classpath to pick up the hsqldb.jar file.
Also note that this will create ...