]> WPIA git - gigi.git/blob - src/org/cacert/gigi/database/GigiPreparedStatement.java
[DB]: Add orgAdmin management code
[gigi.git] / src / org / cacert / gigi / database / GigiPreparedStatement.java
1 package org.cacert.gigi.database;
2
3 import java.sql.Date;
4 import java.sql.PreparedStatement;
5 import java.sql.ResultSet;
6 import java.sql.SQLException;
7 import java.sql.Timestamp;
8
9 public class GigiPreparedStatement {
10
11     PreparedStatement target;
12
13     public GigiPreparedStatement(PreparedStatement preparedStatement) {
14         target = preparedStatement;
15     }
16
17     public GigiResultSet executeQuery() {
18         try {
19             return new GigiResultSet(target.executeQuery());
20         } catch (SQLException e) {
21             handleSQL(e);
22             throw new Error(e);
23         }
24     }
25
26     public int executeUpdate() {
27         try {
28             return target.executeUpdate();
29         } catch (SQLException e) {
30             handleSQL(e);
31             throw new Error(e);
32         }
33     }
34
35     public boolean execute() {
36         try {
37             return target.execute();
38         } catch (SQLException e) {
39             handleSQL(e);
40             throw new Error(e);
41         }
42     }
43
44     public void setInt(int parameterIndex, int x) {
45         try {
46             target.setInt(parameterIndex, x);
47         } catch (SQLException e) {
48             handleSQL(e);
49             throw new Error(e);
50         }
51     }
52
53     public void setString(int parameterIndex, String x) {
54         try {
55             target.setString(parameterIndex, x);
56         } catch (SQLException e) {
57             handleSQL(e);
58             throw new Error(e);
59         }
60     }
61
62     public void setDate(int parameterIndex, Date x) {
63         try {
64             target.setDate(parameterIndex, x);
65         } catch (SQLException e) {
66             handleSQL(e);
67             throw new Error(e);
68         }
69     }
70
71     public void setTimestamp(int parameterIndex, Timestamp x) {
72         try {
73             target.setTimestamp(parameterIndex, x);
74         } catch (SQLException e) {
75             handleSQL(e);
76             throw new Error(e);
77         }
78     }
79
80     public int lastInsertId() {
81         try {
82             ResultSet rs = target.getGeneratedKeys();
83             rs.next();
84             int id = rs.getInt(1);
85             rs.close();
86             return id;
87         } catch (SQLException e) {
88             handleSQL(e);
89             throw new Error(e);
90         }
91     }
92
93     public void setBoolean(int parameterIndex, boolean x) {
94         try {
95             target.setBoolean(parameterIndex, x);
96         } catch (SQLException e) {
97             handleSQL(e);
98             throw new Error(e);
99         }
100     }
101
102     private void handleSQL(SQLException e) {
103         // TODO Auto-generated method stub
104
105     }
106 }