aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2012-10-11 18:52:32 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2012-10-11 18:52:32 +1300
commitcd29641995e256e82828dd6eef44bb83186463c3 (patch)
tree45c4dc3f6eca1f5027c5fe2fe33c1d167ee9253b /src/org/traccar
parent717b60cef1e0bdeacb2f412018a8332a15c25f04 (diff)
downloadtrackermap-server-cd29641995e256e82828dd6eef44bb83186463c3.tar.gz
trackermap-server-cd29641995e256e82828dd6eef44bb83186463c3.tar.bz2
trackermap-server-cd29641995e256e82828dd6eef44bb83186463c3.zip
Fix database generated keys (fix #53)
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/helper/NamedParameterStatement.java10
-rw-r--r--src/org/traccar/model/DatabaseDataManager.java5
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();