Class DatabaseHelper

java.lang.Object
net.simplace.core.service.DatabaseHelper

public final class DatabaseHelper extends Object
Provides static helper methods for database operations, such as copying a table between two connections and reading a query result into memory.
Author:
Andreas Enders
  • Constructor Details

    • DatabaseHelper

      public DatabaseHelper()
  • Method Details

    • copyData

      public static void copyData(boolean doDropBeforeCopy, Connection aSourceConnection, String aSourceTableName, Connection aTargetConnection, String aTargetTableName) throws SQLException
      Copies all rows of a table from one database connection to another. The target table is created with the column names and types of the source table. FLOAT, DOUBLE, INTEGER, character and DATE columns are copied typed, other columns as objects. Finally a CHECKPOINT DEFRAG is executed on the target connection (HSQLDB specific).
      Parameters:
      doDropBeforeCopy - if true, the target table is dropped before it is created
      aSourceConnection - connection to read from
      aSourceTableName - name of the table to copy
      aTargetConnection - connection to write to
      aTargetTableName - name of the table to create and fill
      Throws:
      SQLException - if any database operation fails
    • readResult

      public static LinkedHashMap<String, LinkedList<Object>> readResult(Connection aConnection, String aStatement)
      Executes a query and reads the complete result into memory, organized by column. SQL errors are logged, not thrown.
      Parameters:
      aConnection - database connection to use
      aStatement - SQL query to execute
      Returns:
      map from column label to the list of values of that column, in row order; empty if an error occurred