aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2014-04-22 21:55:26 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2014-04-22 21:55:26 +1200
commit8214596eb5948e6e55de498eaedb67a1a0049481 (patch)
tree27e649f6b0e8ca9f1d9dbcc890612c64f372f871 /src/org/traccar
parent6bbd1a20873eae643b7df61333f2cef5cd57ee39 (diff)
downloadtrackermap-server-8214596eb5948e6e55de498eaedb67a1a0049481.tar.gz
trackermap-server-8214596eb5948e6e55de498eaedb67a1a0049481.tar.bz2
trackermap-server-8214596eb5948e6e55de498eaedb67a1a0049481.zip
Reconnect to database on errors (fix #675)
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/helper/NamedParameterStatement.java25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/org/traccar/helper/NamedParameterStatement.java b/src/org/traccar/helper/NamedParameterStatement.java
index 833f4aea3..f66d8c4dd 100644
--- a/src/org/traccar/helper/NamedParameterStatement.java
+++ b/src/org/traccar/helper/NamedParameterStatement.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2014 Anton Tananaev (anton.tananaev@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,9 +39,11 @@ public class NamedParameterStatement {
/**
* Database connection
*/
- private AdvancedConnection connection;
+ private final AdvancedConnection connection;
private int autoGeneratedKeys;
+
+ private boolean failed;
/**
* Initialize statement
@@ -118,6 +120,7 @@ public class NamedParameterStatement {
connection.reset();
}
statement = connection.getInstance().prepareStatement(parsedQuery, autoGeneratedKeys);
+ failed = false;
}
public void prepare(int autoGeneratedKeys) throws SQLException {
@@ -125,7 +128,7 @@ public class NamedParameterStatement {
try {
if (statement == null) {
reset(false);
- } else if (statement.getWarnings() != null) {
+ } else if (failed || statement.getWarnings() != null) {
reset(true);
}
} catch (SQLException firstError) {
@@ -133,6 +136,7 @@ public class NamedParameterStatement {
reset(true);
} catch (SQLException secondError) {
Log.warning(secondError);
+ failed = true;
throw secondError;
}
}
@@ -146,15 +150,24 @@ public class NamedParameterStatement {
* Execute query with result
*/
public ResultSet executeQuery() throws SQLException {
- return statement.executeQuery();
+ try {
+ return statement.executeQuery();
+ } catch (SQLException error) {
+ failed = true;
+ throw error;
+ }
}
-
/**
* Executes query without result
*/
public int executeUpdate() throws SQLException {
- return statement.executeUpdate();
+ try {
+ return statement.executeUpdate();
+ } catch (SQLException error) {
+ failed = true;
+ throw error;
+ }
}
/**