diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/org/traccar/helper/NamedParameterStatement.java | 10 | ||||
-rw-r--r-- | src/org/traccar/model/DatabaseDataManager.java | 5 |
2 files changed, 9 insertions, 6 deletions
diff --git a/src/org/traccar/helper/NamedParameterStatement.java b/src/org/traccar/helper/NamedParameterStatement.java index a4b1a12c6..0dfbb9551 100644 --- a/src/org/traccar/helper/NamedParameterStatement.java +++ b/src/org/traccar/helper/NamedParameterStatement.java @@ -107,17 +107,21 @@ public class NamedParameterStatement { return parsedQuery.toString(); } - public void prepare() throws SQLException { + public void prepare(int autoGeneratedKeys) throws SQLException { try { if (statement == null) { - statement = connection.getInstance().prepareStatement(parsedQuery); + statement = connection.getInstance().prepareStatement(parsedQuery, autoGeneratedKeys); } } catch (SQLException error) { connection.reset(); - statement = connection.getInstance().prepareStatement(parsedQuery); + statement = connection.getInstance().prepareStatement(parsedQuery, autoGeneratedKeys); } } + public void prepare() throws SQLException { + prepare(Statement.NO_GENERATED_KEYS); + } + /** * Execute query with result */ diff --git a/src/org/traccar/model/DatabaseDataManager.java b/src/org/traccar/model/DatabaseDataManager.java index 384d87828..7521828a3 100644 --- a/src/org/traccar/model/DatabaseDataManager.java +++ b/src/org/traccar/model/DatabaseDataManager.java @@ -15,8 +15,7 @@ */ package org.traccar.model; -import java.sql.ResultSet; -import java.sql.SQLException; +import java.sql.*; import java.util.*; import org.traccar.helper.AdvancedConnection; import org.traccar.helper.Log; @@ -130,7 +129,7 @@ public class DatabaseDataManager implements DataManager { public synchronized void addDevice(Device device) throws SQLException { - queryAddDevice.prepare(); + queryAddDevice.prepare(Statement.RETURN_GENERATED_KEYS); queryAddDevice.setString("imei", device.getImei()); queryAddDevice.executeUpdate(); |