diff options
Diffstat (limited to 'src/org/traccar/helper/NamedParameterStatement.java')
-rw-r--r-- | src/org/traccar/helper/NamedParameterStatement.java | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/org/traccar/helper/NamedParameterStatement.java b/src/org/traccar/helper/NamedParameterStatement.java index 0dfbb9551..cbbc187da 100644 --- a/src/org/traccar/helper/NamedParameterStatement.java +++ b/src/org/traccar/helper/NamedParameterStatement.java @@ -40,6 +40,8 @@ public class NamedParameterStatement { * Database connection */ private AdvancedConnection connection; + + private int autoGeneratedKeys; /** * Initialize statement @@ -106,15 +108,30 @@ public class NamedParameterStatement { return parsedQuery.toString(); } + + public void reset(boolean resetConnection) throws SQLException { + if (statement != null) { + statement.close(); + statement = null; + } + if (resetConnection) { + connection.reset(); + } + statement = connection.getInstance().prepareStatement(parsedQuery, autoGeneratedKeys); + } public void prepare(int autoGeneratedKeys) throws SQLException { + this.autoGeneratedKeys = autoGeneratedKeys; try { if (statement == null) { - statement = connection.getInstance().prepareStatement(parsedQuery, autoGeneratedKeys); + reset(false); + } else if (statement.getWarnings() != null) { + reset(true); } } catch (SQLException error) { - connection.reset(); - statement = connection.getInstance().prepareStatement(parsedQuery, autoGeneratedKeys); + Log.info("Exception during query preparation"); + Log.warning(error.getMessage()); + reset(true); } } |