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) {
25 target = DatabaseConnection.getInstance().prepareInternal(stmt, scroll);
26 } catch (SQLException e) {
31 public GigiResultSet executeQuery() {
33 return rs = new GigiResultSet(target.executeQuery());
34 } catch (SQLException e) {
40 public void executeUpdate() {
42 int updated = target.executeUpdate();
44 throw new Error("FATAL: multiple or no data updated: " + updated);
46 } catch (SQLException e) {
52 public boolean execute() {
54 return target.execute();
55 } catch (SQLException e) {
61 public void setInt(int parameterIndex, int x) {
63 target.setInt(parameterIndex, x);
64 } catch (SQLException e) {
70 public void setString(int parameterIndex, String x) {
72 target.setString(parameterIndex, x);
73 } catch (SQLException e) {
79 public void setDate(int parameterIndex, Date x) {
81 target.setDate(parameterIndex, x);
82 } catch (SQLException e) {
88 public void setTimestamp(int parameterIndex, Timestamp x) {
90 target.setTimestamp(parameterIndex, x);
91 } catch (SQLException e) {
97 public int lastInsertId() {
99 ResultSet rs = target.getGeneratedKeys();
101 int id = rs.getInt(1);
104 } catch (SQLException e) {
110 public void setBoolean(int parameterIndex, boolean x) {
112 target.setBoolean(parameterIndex, x);
113 } catch (SQLException e) {
119 private void handleSQL(SQLException e) {
120 // TODO Auto-generated method stub
125 public void close() {
126 GigiResultSet r = rs;
130 PreparedStatement tg = target;
133 DatabaseConnection.getInstance().returnStatement(tg);
134 } catch (SQLException e) {