]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/database/DatabaseConnection.java
FIX: wrong set of the emailFiled (and so the city field) in Certificate
[gigi.git] / src / org / cacert / gigi / database / DatabaseConnection.java
index 21d701cb4bc4048589fcd845040e5660a405912d..abeb78d0d765d7888af97e79a8bd1550e65a869e 100644 (file)
@@ -15,7 +15,7 @@ public class DatabaseConnection {
 
     private Connection c;
 
-    private HashMap<String, PreparedStatement> statements = new HashMap<String, PreparedStatement>();
+    private HashMap<String, GigiPreparedStatement> statements = new HashMap<String, GigiPreparedStatement>();
 
     private static Properties credentials;
 
@@ -44,11 +44,15 @@ public class DatabaseConnection {
         }
     }
 
-    public PreparedStatement prepare(String query) throws SQLException {
+    public GigiPreparedStatement prepare(String query) {
         ensureOpen();
-        PreparedStatement statement = statements.get(query);
+        GigiPreparedStatement statement = statements.get(query);
         if (statement == null) {
-            statement = c.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
+            try {
+                statement = new GigiPreparedStatement(c.prepareStatement(query, Statement.RETURN_GENERATED_KEYS));
+            } catch (SQLException e) {
+                throw new Error(e);
+            }
             statements.put(query, statement);
         }
         return statement;
@@ -71,14 +75,6 @@ public class DatabaseConnection {
         lastAction = System.currentTimeMillis();
     }
 
-    public static int lastInsertId(PreparedStatement query) throws SQLException {
-        ResultSet rs = query.getGeneratedKeys();
-        rs.next();
-        int id = rs.getInt(1);
-        rs.close();
-        return id;
-    }
-
     private static ThreadLocal<DatabaseConnection> instances = new ThreadLocal<DatabaseConnection>() {
 
         @Override