summaryrefslogtreecommitdiffstats
path: root/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/MysqlStatement.java
diff options
context:
space:
mode:
Diffstat (limited to 'dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/MysqlStatement.java')
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/MysqlStatement.java44
1 files changed, 44 insertions, 0 deletions
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/MysqlStatement.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/MysqlStatement.java
index 1d1bbc18..a5d0f49d 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/MysqlStatement.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/MysqlStatement.java
@@ -5,6 +5,7 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
@@ -42,6 +43,11 @@ public class MysqlStatement implements Closeable {
this.query = query;
this.statement = con.prepareStatement(query.sql);
}
+
+ public String getQuery()
+ {
+ return query.sql;
+ }
/**
* Returns the indexes for a parameter.
@@ -190,6 +196,39 @@ public class MysqlStatement implements Closeable {
public int executeUpdate() throws SQLException {
return statement.executeUpdate();
}
+
+ /**
+ * Retrieves any auto-generated keys created as a result of executing this
+ * <code>Statement</code> object. If this <code>Statement</code> object did
+ * not generate any keys, an empty <code>ResultSet</code>
+ * object is returned.
+ *
+ * <p>
+ * <B>Note:</B>If the columns which represent the auto-generated keys were not specified,
+ * the JDBC driver implementation will determine the columns which best represent the
+ * auto-generated keys.
+ *
+ * @return a <code>ResultSet</code> object containing the auto-generated key(s)
+ * generated by the execution of this <code>Statement</code> object
+ * @exception SQLException if a database access error occurs or
+ * this method is called on a closed <code>Statement</code>
+ * @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
+ */
+ public ResultSet getGeneratedKeys() throws SQLException {
+ ResultSet rs = statement.getGeneratedKeys();
+ openResultSets.add(rs);
+ return rs;
+ }
+
+ public int lastInsertId() throws SQLException {
+ int result = -1;
+ try (ResultSet rs = statement.getGeneratedKeys()) {
+ if (rs.next()) {
+ result = rs.getInt(1);
+ }
+ }
+ return result;
+ }
/**
* Closes the statement.
@@ -206,6 +245,11 @@ public class MysqlStatement implements Closeable {
}
}
try {
+ statement.cancel();
+ } catch (SQLException e) {
+ // Nothing to do
+ }
+ try {
statement.close();
} catch (SQLException e) {
// Nothing to do