aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/helper
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/helper')
-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;
+ }
}
/**