Oct 11

The DBUtil library from Apache provides a set of class for doing a variety of standard database tasks.

eg. To make a query becomes as simple as the following, providing the result set as a List of arrays where each list elements contains a row.

QueryRunner runner = new QueryRunner();
ArrayListHandler handler = new ArrayListHandler();
List<Object[]> result = runner.query(connection,
    "SELECT * FROM MyTable WHERE name=?", handler, "Joe Smith");

written by objects \\ tags: , , , ,

Jun 04

If you are pulling a value from a database ResultSet it is somethimes not possible to check the value returned to determine if the value in the database was null. In these cases you can use the wasNull() method to check.
The wasNull() method will return true if the value in the database was NULL for the last value retrieved from ResultSet.

Here is an example of its usage.

ResultSet rs = statement.executeQuery();
int value = rs.getInt(1);
if (rs.wasNull(1))
   // Database contains NULL

written by objects \\ tags: , ,

Jan 31

Swing is single thread so you are best to load the data from the ResultSet in a separate thread. And because it is a different thread than Swing’s Event Dispatch Thread you’ll need to ensure each entry to be added to the list is added from the EDT.

The SwingWorker class can be used to handle tasks like this.

Let us know if you’d like to see some example code.

written by objects \\ tags: ,