From 4eb88253787e895a3b0e22b2cbde04cd1b6d88ae Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 3 Jul 2015 09:07:04 +1200 Subject: Fix no generated keys problem --- src/org/traccar/database/QueryBuilder.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/org/traccar/database') diff --git a/src/org/traccar/database/QueryBuilder.java b/src/org/traccar/database/QueryBuilder.java index 5e5c163a3..04e29d7a2 100644 --- a/src/org/traccar/database/QueryBuilder.java +++ b/src/org/traccar/database/QueryBuilder.java @@ -40,11 +40,13 @@ public class QueryBuilder { private final Connection connection; private PreparedStatement statement; private final String query; + private final boolean returnGeneratedKeys; private QueryBuilder(DataSource dataSource, String query, boolean returnGeneratedKeys) throws SQLException { indexMap = new HashMap>(); connection = dataSource.getConnection(); this.query = query; + this.returnGeneratedKeys = returnGeneratedKeys; if (query != null) { String parsedQuery = parse(query.trim(), indexMap); try { @@ -417,9 +419,11 @@ public class QueryBuilder { if (query != null) { try { statement.executeUpdate(); - ResultSet resultSet = statement.getGeneratedKeys(); - if (resultSet.next()) { - return resultSet.getLong(1); + if (returnGeneratedKeys) { + ResultSet resultSet = statement.getGeneratedKeys(); + if (resultSet.next()) { + return resultSet.getLong(1); + } } } finally { statement.close(); -- cgit v1.2.3