aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/Server.java3
-rw-r--r--src/org/traccar/helper/NamedParameterStatement.java21
2 files changed, 11 insertions, 13 deletions
diff --git a/src/org/traccar/Server.java b/src/org/traccar/Server.java
index f2c5752f5..94e6f7ac3 100644
--- a/src/org/traccar/Server.java
+++ b/src/org/traccar/Server.java
@@ -142,6 +142,7 @@ public class Server implements DataManager {
List deviceList = new LinkedList();
+ selectDevice.prepare();
ResultSet result = selectDevice.executeQuery();
while (result.next()) {
Device device = new Device();
@@ -168,6 +169,8 @@ public class Server implements DataManager {
}
public synchronized void setPosition(Position position) throws SQLException {
+
+ insertPosition.prepare();
insertPosition.setLong("device_id", position.getDeviceId());
insertPosition.setTimestamp("time", position.getTime());
diff --git a/src/org/traccar/helper/NamedParameterStatement.java b/src/org/traccar/helper/NamedParameterStatement.java
index bbb2bcdf3..5fbc57d78 100644
--- a/src/org/traccar/helper/NamedParameterStatement.java
+++ b/src/org/traccar/helper/NamedParameterStatement.java
@@ -114,11 +114,8 @@ public class NamedParameterStatement {
return parsedQuery.toString();
}
-
- /**
- * Execute query with result
- */
- public ResultSet executeQuery() throws SQLException {
+
+ public void prepare() throws SQLException {
try {
if (statement == null) {
statement = connection.getInstance().prepareStatement(parsedQuery);
@@ -127,6 +124,12 @@ public class NamedParameterStatement {
connection.reset();
statement = connection.getInstance().prepareStatement(parsedQuery);
}
+ }
+
+ /**
+ * Execute query with result
+ */
+ public ResultSet executeQuery() throws SQLException {
return statement.executeQuery();
}
@@ -135,14 +138,6 @@ public class NamedParameterStatement {
* Executes query without result
*/
public int executeUpdate() throws SQLException {
- try {
- if (statement == null) {
- statement = connection.getInstance().prepareStatement(parsedQuery);
- }
- } catch (SQLException error) {
- connection.reset();
- statement = connection.getInstance().prepareStatement(parsedQuery);
- }
return statement.executeUpdate();
}