1 package org.cacert.gigi.database;
4 import java.sql.PreparedStatement;
5 import java.sql.ResultSet;
6 import java.sql.SQLException;
7 import java.sql.Timestamp;
9 public class GigiPreparedStatement implements AutoCloseable {
11 private PreparedStatement target;
13 private GigiResultSet rs;
15 protected GigiPreparedStatement(PreparedStatement preparedStatement) {
16 target = preparedStatement;
19 public GigiPreparedStatement(String stmt) {
23 public GigiPreparedStatement(String stmt, boolean scroll) {
26 target = DatabaseConnection.getInstance().prepareInternalScrollable(stmt);
28 target = DatabaseConnection.getInstance().prepareInternal(stmt);
30 } catch (SQLException e) {
35 public GigiResultSet executeQuery() {
37 return rs = new GigiResultSet(target.executeQuery());
38 } catch (SQLException e) {
44 public void executeUpdate() {
46 int updated = target.executeUpdate();
48 throw new Error("FATAL: multiple or no data updated: " + updated);
50 } catch (SQLException e) {
56 public boolean execute() {
58 return target.execute();
59 } catch (SQLException e) {
65 public void setInt(int parameterIndex, int x) {
67 target.setInt(parameterIndex, x);
68 } catch (SQLException e) {
74 public void setString(int parameterIndex, String x) {
76 target.setString(parameterIndex, x);
77 } catch (SQLException e) {
83 public void setDate(int parameterIndex, Date x) {
85 target.setDate(parameterIndex, x);
86 } catch (SQLException e) {
92 public void setTimestamp(int parameterIndex, Timestamp x) {
94 target.setTimestamp(parameterIndex, x);
95 } catch (SQLException e) {
101 public int lastInsertId() {
103 ResultSet rs = target.getGeneratedKeys();
105 int id = rs.getInt(1);
108 } catch (SQLException e) {
114 public void setBoolean(int parameterIndex, boolean x) {
116 target.setBoolean(parameterIndex, x);
117 } catch (SQLException e) {
123 private void handleSQL(SQLException e) {
124 // TODO Auto-generated method stub
129 public void close() {
130 GigiResultSet r = rs;
134 PreparedStatement tg = target;
136 DatabaseConnection.getInstance().returnStatement(tg);