Class DatabaseHelper
java.lang.Object
net.simplace.core.service.DatabaseHelper
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcopyData(boolean doDropBeforeCopy, Connection aSourceConnection, String aSourceTableName, Connection aTargetConnection, String aTargetTableName) Copies all rows of a table from one database connection to another.static LinkedHashMap<String, LinkedList<Object>> readResult(Connection aConnection, String aStatement) Executes a query and reads the complete result into memory, organized by column.
-
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 aCHECKPOINT DEFRAGis executed on the target connection (HSQLDB specific).- Parameters:
doDropBeforeCopy- iftrue, the target table is dropped before it is createdaSourceConnection- connection to read fromaSourceTableName- name of the table to copyaTargetConnection- connection to write toaTargetTableName- 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 useaStatement- 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
-