fix connection close issue
This commit is contained in:
parent
883365227b
commit
04d5338294
Binary file not shown.
@ -1,7 +1,7 @@
|
||||
mqtt.broker = tcp://172.16.2.15:1883
|
||||
;mqtt.broker = tcp://eupenstrasse20.dynamic.hottis.de:2883
|
||||
;mqtt.username = tron
|
||||
;mqtt.password = geheim123
|
||||
;mqtt.broker = tcp://172.16.2.15:1883
|
||||
mqtt.broker = tcp://eupenstrasse20.dynamic.hottis.de:2883
|
||||
mqtt.username = tron
|
||||
mqtt.password = geheim123
|
||||
|
||||
mbus.dataparser.1 = light,Light,de.hottis.measurementCollector.FinderOnePhasePowerMeter
|
||||
mbus.dataparser.2 = computer,Computer,de.hottis.measurementCollector.FinderOnePhasePowerMeter
|
||||
@ -14,4 +14,5 @@ mbus.dataparser.8 = thermom.,null,de.hottis.measurementCollector.HottisFourChann
|
||||
|
||||
jms.broker = tcp://localhost:61616
|
||||
jms.clientid = mcol
|
||||
jms.parseddata.topic = IoT/Measurement
|
||||
jms.parseddata.topic = IoT/Measurement
|
||||
|
||||
|
@ -124,6 +124,8 @@ public class DatabaseEngine extends Thread implements ITriggerable {
|
||||
try {
|
||||
int itemCnt = 0;
|
||||
|
||||
dbCon = DriverManager.getConnection(dbUrl, dbUsername, dbPassword);
|
||||
logger.debug("New connection opened: " + dbCon);
|
||||
while (true) {
|
||||
try {
|
||||
ADataObject ado = queue.dequeue();
|
||||
@ -131,15 +133,16 @@ public class DatabaseEngine extends Thread implements ITriggerable {
|
||||
logger.warn("DatabaseEngine found no data");
|
||||
break;
|
||||
}
|
||||
dbCon = DriverManager.getConnection(dbUrl, dbUsername, dbPassword);
|
||||
|
||||
String key = ado.getClass().getName();
|
||||
PreparedStatement pstmt;
|
||||
if (! preparedStatements.containsKey(key)) {
|
||||
pstmt = dbCon.prepareStatement(createStatementFromDataObject(ado));
|
||||
preparedStatements.put(key, pstmt);
|
||||
logger.debug("PreparedStatement created for " + key + ": " + pstmt);
|
||||
} else {
|
||||
pstmt = preparedStatements.get(key);
|
||||
logger.debug("PreparedStatement reused for " + key + ": " + pstmt);
|
||||
}
|
||||
bindValue(pstmt, 1, ado.getName());
|
||||
bindValue(pstmt, 2, ado.getTimestamp());
|
||||
@ -163,6 +166,7 @@ public class DatabaseEngine extends Thread implements ITriggerable {
|
||||
} finally {
|
||||
for (PreparedStatement p : preparedStatements.values()) {
|
||||
try {
|
||||
logger.debug("PreparedStatement " + p + " about to close");
|
||||
p.close();
|
||||
} catch (SQLException e) {
|
||||
logger.warn("SQLException when closing prepared statement, nothing will be done");
|
||||
@ -171,6 +175,7 @@ public class DatabaseEngine extends Thread implements ITriggerable {
|
||||
preparedStatements.clear();
|
||||
if (dbCon != null) {
|
||||
try {
|
||||
logger.debug("Connection " + dbCon + " about to close");
|
||||
dbCon.close();
|
||||
} catch (SQLException e) {
|
||||
logger.warn("SQLException when closing connection, nothing will be done");
|
||||
|
Loading…
x
Reference in New Issue
Block a user