Note: right-click or shift-click on the links to download
the associated file. All code is freely available for unrestricted use.
Remember that you need the proper drivers to use this code.
You almost certainly will change it slightly to reflect your
drivers.
FruitTest.java
A class that connects to either an Oracle or
a Sybase database and prints out the values of
predetermined columns in the "fruits" table.
DriverUtilities.java
Some simple utilities for building Oracle and Sybase
JDBC connections. This is not general-purpose
code -- it is specific to our local setup.
FruitCreation.java
Creates a simple table named fruits in either
an Oracle or a Sybase database.
DatabaseUtilities.java
Several general-purpose utilities discussed and
used in the chapter.
DBResults.java
Class to store completed results of a JDBC Query.
Differs from a ResultSet in several ways:
ResultSet doesn’t necessarily have all the data;
reconnection to database occurs as you ask for
later rows.
This class stores results as strings, in arrays.
This class includes DatabaseMetaData (database product
name and version) and ResultSetMetaData
(the column names).
This class has a toHTMLTable method that turns
the results into a long string corresponding to
an HTML table.
EmployeeTest.java
A test case for the database utilities. Prints results in plain
text.
EmployeeTest2.java
A test case for the database utilities. Prints results formatted
as an HTML table.
EmployeeCreation.java
Make a simple "employees" table using the database utilities of
the chapter.
QueryViewer.java
An interactive database query viewer. Connects to
the specified Oracle or Sybase database, executes a query,
and presents the results in a JTable. Uses the following file:
DBResultsTableModel.java
Simple class that tells a JTable how to extract
relevant data from a DBResults
object (which is used to store the results from a database query).
PreparedStatements.java
An example to test the timing differences resulting
from repeated raw queries vs. repeated calls to
prepared statements. These results may vary dramatically
among database servers and drivers.