X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2Fdatabase%2FGigiPreparedStatement.java;h=eae804b800d20fb6cc29de98ff3c56a624b56a66;hb=c4d3f24d14399e48026850fd69b15bd108c020e4;hp=55ed6ad3d53d003ae6639c575dc19147a36cdfd0;hpb=ec24cf6925bb3729a644580ad4a9375d05883c62;p=gigi.git diff --git a/src/org/cacert/gigi/database/GigiPreparedStatement.java b/src/org/cacert/gigi/database/GigiPreparedStatement.java index 55ed6ad3..eae804b8 100644 --- a/src/org/cacert/gigi/database/GigiPreparedStatement.java +++ b/src/org/cacert/gigi/database/GigiPreparedStatement.java @@ -6,17 +6,31 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; -public class GigiPreparedStatement { +public class GigiPreparedStatement implements AutoCloseable { - PreparedStatement target; + private PreparedStatement target; - public GigiPreparedStatement(PreparedStatement preparedStatement) { + private GigiResultSet rs; + + protected GigiPreparedStatement(PreparedStatement preparedStatement) { target = preparedStatement; } + public GigiPreparedStatement(String stmt) { + this(stmt, false); + } + + public GigiPreparedStatement(String stmt, boolean scroll) { + try { + target = DatabaseConnection.getInstance().prepareInternal(stmt, scroll); + } catch (SQLException e) { + throw new Error(e); + } + } + public GigiResultSet executeQuery() { try { - return new GigiResultSet(target.executeQuery()); + return rs = new GigiResultSet(target.executeQuery()); } catch (SQLException e) { handleSQL(e); throw new Error(e); @@ -106,4 +120,21 @@ public class GigiPreparedStatement { // TODO Auto-generated method stub } + + @Override + public void close() { + GigiResultSet r = rs; + if (r != null) { + r.close(); + } + PreparedStatement tg = target; + target = null; + try { + DatabaseConnection.getInstance().returnStatement(tg); + } catch (SQLException e) { + throw new Error(e); + } + + } + }