public class SimpleDatabaseConnector extends Object
SimpleDatabaseConnector can store multiple select queries in offline cache (map of SQL-Query(key) and Result (value)).
IDatabaseConnector sdc = newSqlConnectorInstance(getDatabaseConnectionParameters("EnxMasterdata"), true); // use false to disable cache
if (sdc.openDatabase() || sdc.isOffline()) { // if cache is disabled you should stop if isOffline() == true
List<Map<String, String>> selectedRows = sdc.executeSelectQuery(true, sqlGattungString);
for (Map<String, String> tableEntry : selectedRows) {
isin2enx.put(tableEntry.get("isin"), tableEntry.get("enx_code"));
}
}
| Constructor and Description |
|---|
SimpleDatabaseConnector(DbConnParms _connectionParams) |
| Modifier and Type | Method and Description |
|---|---|
void |
closeDatabase()
Closes the database connection if it was previously connected.
|
PreparedStatement |
createPreparedStatement(String _sql)
Creates a prepared statement which can be used for batch statements.
|
boolean |
executeBatchQuery(String _sqlQuery,
List<Object[]> _sqlParameters,
int _batchSize)
Run update/inserts as batch update.
|
boolean |
executeQuery(PreparedStatement _ps)
Execute a previously created prepared statement (update or delete).
|
boolean |
executeQuery(String _sql,
Object... _args)
Executes an sql query.
|
List<Map<String,String>> |
executeSelectQuery(String _sql,
Object... _args)
Returns the result of an SQL Select-PreparedStatement as list of maps where each key in the map is a column.
|
Connection |
getDbConnection() |
boolean |
isAutoCommit() |
boolean |
isDbOpen()
Returns true if database has been opened.
|
boolean |
isSupportsBatch() |
boolean |
openDatabase()
Trys to open a connection to the given database parameters.
|
void |
setAutoCommit(boolean _onOff)
Enable/Disable autocommit on database connection.
|
String |
toString() |
public SimpleDatabaseConnector(DbConnParms _connectionParams)
public final boolean openDatabase()
throws InvalidClassException,
ClassNotFoundException
InvalidClassExceptionClassNotFoundExceptionpublic Connection getDbConnection()
public void closeDatabase()
throws SQLException
SQLExceptionpublic boolean isDbOpen()
public boolean executeBatchQuery(String _sqlQuery, List<Object[]> _sqlParameters, int _batchSize)
_sqlQuery - sql query to use (with '?' placeholders)_sqlParameters - an array of values for replacing '?' placeholders in query_batchSize - batch size to usepublic boolean executeQuery(String _sql, Object... _args)
_sql - _args - public List<Map<String,String>> executeSelectQuery(String _sql, Object... _args)
_sql - the sql statement to execute (can use '?' placeholder which will be replaced by the parameters in _args)_args - parameters to replace '?'- placeholder insert _sql (if none, this can be omitted)public PreparedStatement createPreparedStatement(String _sql)
_sql - public boolean executeQuery(PreparedStatement _ps)
_ps - public boolean isSupportsBatch()
public void setAutoCommit(boolean _onOff)
throws SQLException
SQLExceptionpublic boolean isAutoCommit()
throws SQLException
SQLExceptionCopyright © 2018. All rights reserved.