KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nilostep > xlsql > jdbc > xlPreparedStatement


1 /*
2  * x l S Q L
3  * (c) Jim Caprioli, NiLOSTEP.com
4  * See xlSQL-license.txt for license details
5  *
6  */

7 package com.nilostep.xlsql.jdbc;
8
9 import java.sql.*;
10 import com.nilostep.xlsql.sql.*;
11
12 public class xlPreparedStatement extends xlStatement implements PreparedStatement {
13
14     private String JavaDoc psql;
15     private PreparedStatement dbPstm;
16     
17     //~ Constructors ···························································
18

19     /**
20     * Constructs a new PreparedStatementImpl object.
21     *
22     */

23     protected xlPreparedStatement(xlConnection con, PreparedStatement pstm,
24                                              String JavaDoc sql) throws SQLException {
25         super(con,pstm);
26         dbPstm = pstm;
27         psql = sql;
28     }
29
30     //~ Methods ································································
31

32     /**
33     * Implements method in interface java.sql.PreparedStatement
34     * @see java.sql.PreparedStatement#addBatch
35     */

36     public void addBatch() throws SQLException {
37         dbPstm.addBatch();
38     }
39
40     /**
41     * Implements method in interface java.sql.PreparedStatement
42     * @see java.sql.PreparedStatement#clearParameters
43     */

44     public void clearParameters() throws SQLException {
45         dbPstm.clearParameters();
46     }
47
48     /**
49     * Implements method in interface java.sql.PreparedStatement
50     * @see java.sql.PreparedStatement#execute
51     */

52     public boolean execute() throws SQLException {
53         boolean ret;
54         xlSqlCommand cmd = xlCon.xlsql.parseSql(psql);
55         if (cmd.execAllowed()) {
56             // dbStm may throw an SQLException..., pass on to client
57
ret = dbPstm.execute();
58             cmd.execute();
59         }
60         else {
61             throw new SQLException("xlSQL: execute not allowed");
62         }
63         return ret;
64     }
65
66     /**
67     * Implements method in interface java.sql.PreparedStatement
68     * @see java.sql.PreparedStatement#execute
69     */

70     public boolean execute(String JavaDoc sql, int autoGeneratedKeys)
71                     throws SQLException {
72         boolean ret;
73         xlSqlCommand cmd = xlCon.xlsql.parseSql(sql);
74         if (cmd.execAllowed()) {
75             // dbStm may throw an SQLException..., pass on to client
76
ret = dbPstm.execute(sql);
77             cmd.execute();
78         }
79         else {
80             throw new SQLException("xlSQL: execute not allowed");
81         }
82         return ret;
83     }
84
85     /**
86     * Implements method in interface java.sql.PreparedStatement
87     * @see java.sql.PreparedStatement#executeQuery
88     */

89     public ResultSet executeQuery() throws SQLException {
90         ResultSet ret = dbPstm.executeQuery();
91         return ret;
92     }
93
94     /**
95     * Implements method in interface java.sql.PreparedStatement
96     * @see java.sql.PreparedStatement#executeUpdate
97     */

98     public int executeUpdate() throws SQLException {
99         int ret;
100         xlSqlCommand cmd = xlCon.xlsql.parseSql(psql);
101         if (cmd.execAllowed()) {
102             // dbStm may throw an SQLException..., pass on to client
103
ret = dbPstm.executeUpdate(psql);
104             cmd.execute();
105         }
106         else {
107             throw new SQLException("xlSQL: execute not allowed");
108         }
109         return ret;
110     }
111
112     /**
113     * Implements method in interface java.sql.PreparedStatement
114     * @see java.sql.PreparedStatement#getMetaData
115     */

116     public ResultSetMetaData getMetaData() throws SQLException {
117         return dbPstm.getMetaData();
118     }
119
120     /**
121     * Implements method in interface java.sql.PreparedStatement
122     * @see java.sql.PreparedStatement#getParameterMetaData
123     */

124     public ParameterMetaData getParameterMetaData() throws SQLException {
125         ParameterMetaData dbPsMeta = dbPstm.getParameterMetaData();
126         ParameterMetaData psMeta = new xlParameterMetaData(this, dbPsMeta);
127         return psMeta;
128     }
129
130     /**
131     * Implements method in interface java.sql.PreparedStatement
132     * @see java.sql.PreparedStatement#setArray
133     */

134     public void setArray(int i, Array x) throws SQLException {
135         dbPstm.setArray(i, x);
136     }
137
138     /**
139     * Implements method in interface java.sql.PreparedStatement
140     * @see java.sql.PreparedStatement#setAsciiStream
141     */

142     public void setAsciiStream(int parameterIndex, java.io.InputStream JavaDoc x,
143                                int length) throws SQLException {
144         dbPstm.setAsciiStream(parameterIndex, x, length);
145     }
146
147     /**
148     * Implements method in interface java.sql.PreparedStatement
149     * @see java.sql.PreparedStatement#setBigDecimal
150     */

151     public void setBigDecimal(int parameterIndex, java.math.BigDecimal JavaDoc x)
152                        throws SQLException {
153         dbPstm.setBigDecimal(parameterIndex, x);
154     }
155
156     /**
157     * Implements method in interface java.sql.PreparedStatement
158     * @see java.sql.PreparedStatement#setBinaryStream
159     */

160     public void setBinaryStream(int parameterIndex, java.io.InputStream JavaDoc x,
161                                 int length) throws SQLException {
162         dbPstm.setBinaryStream(parameterIndex, x, length);
163     }
164
165     /**
166     * Implements method in interface java.sql.PreparedStatement
167     * @see java.sql.PreparedStatement#setBlob
168     */

169     public void setBlob(int i, Blob x) throws SQLException {
170         dbPstm.setBlob(i, x);
171     }
172
173     /**
174     * Implements method in interface java.sql.PreparedStatement
175     * @see java.sql.PreparedStatement#setBoolean
176     */

177     public void setBoolean(int parameterIndex, boolean x)
178                     throws SQLException {
179         dbPstm.setBoolean(parameterIndex, x);
180     }
181
182     /**
183     * Implements method in interface java.sql.PreparedStatement
184     * @see java.sql.PreparedStatement#setByte
185     */

186     public void setByte(int parameterIndex, byte x) throws SQLException {
187         dbPstm.setByte(parameterIndex, x);
188     }
189
190     /**
191     * Implements method in interface java.sql.PreparedStatement
192     * @see java.sql.PreparedStatement#setBytes
193     */

194     public void setBytes(int parameterIndex, byte[] x)
195                   throws SQLException {
196         dbPstm.setBytes(parameterIndex, x);
197     }
198
199     /**
200     * Implements method in interface java.sql.PreparedStatement
201     * @see java.sql.PreparedStatement#setCharacterStream
202     */

203     public void setCharacterStream(int parameterIndex, java.io.Reader JavaDoc reader,
204                                    int length) throws SQLException {
205         dbPstm.setCharacterStream(parameterIndex, reader, length);
206     }
207
208     /**
209     * Implements method in interface java.sql.PreparedStatement
210     * @see java.sql.PreparedStatement#setClob
211     */

212     public void setClob(int i, Clob x) throws SQLException {
213         dbPstm.setClob(i, x);
214     }
215
216     /**
217     * Implements method in interface java.sql.PreparedStatement
218     * @see java.sql.PreparedStatement#setCursorName
219     */

220     public void setCursorName(String JavaDoc name) throws SQLException {
221         dbPstm.setCursorName(name);
222     }
223
224     /**
225     * Implements method in interface java.sql.PreparedStatement
226     * @see java.sql.PreparedStatement#setDate
227     */

228     public void setDate(int parameterIndex, java.sql.Date JavaDoc x)
229                  throws SQLException {
230         dbPstm.setDate(parameterIndex, x);
231     }
232
233     /**
234     * Implements method in interface java.sql.PreparedStatement
235     * @see java.sql.PreparedStatement#setDate
236     */

237     public void setDate(int parameterIndex, java.sql.Date JavaDoc x,
238                         java.util.Calendar JavaDoc cal) throws SQLException {
239         dbPstm.setDate(parameterIndex, x, cal);
240     }
241
242     /**
243     * Implements method in interface java.sql.PreparedStatement
244     * @see java.sql.PreparedStatement#setDouble
245     */

246     public void setDouble(int parameterIndex, double x)
247                    throws SQLException {
248         dbPstm.setDouble(parameterIndex, x);
249     }
250
251     /**
252     * Implements method in interface java.sql.PreparedStatement
253     * @see java.sql.PreparedStatement#setFloat
254     */

255     public void setFloat(int parameterIndex, float x) throws SQLException {
256         dbPstm.setFloat(parameterIndex, x);
257     }
258
259     /**
260     * Implements method in interface java.sql.PreparedStatement
261     * @see java.sql.PreparedStatement#setInt
262     */

263     public void setInt(int parameterIndex, int x) throws SQLException {
264         dbPstm.setInt(parameterIndex, x);
265     }
266
267     /**
268     * Implements method in interface java.sql.PreparedStatement
269     * @see java.sql.PreparedStatement#setLong
270     */

271     public void setLong(int parameterIndex, long x) throws SQLException {
272          dbPstm.setLong(parameterIndex, x);
273    }
274
275     /**
276     * Implements method in interface java.sql.PreparedStatement
277     * @see java.sql.PreparedStatement#setNull
278     */

279     public void setNull(int parameterIndex, int sqlType)
280                  throws SQLException {
281         dbPstm.setNull(parameterIndex, sqlType);
282     }
283
284     /**
285     * Implements method in interface java.sql.PreparedStatement
286     * @see java.sql.PreparedStatement#setNull
287     */

288     public void setNull(int paramIndex, int sqlType, String JavaDoc typeName)
289                  throws SQLException {
290         dbPstm.setNull(paramIndex, sqlType, typeName);
291     }
292
293     /**
294     * Implements method in interface java.sql.PreparedStatement
295     * @see java.sql.PreparedStatement#setObject
296     */

297     public void setObject(int parameterIndex, Object JavaDoc x)
298                    throws SQLException {
299         dbPstm.setObject(parameterIndex, x);
300     }
301
302     /**
303     * Implements method in interface java.sql.PreparedStatement
304     * @see java.sql.PreparedStatement#setObject
305     */

306     public void setObject(int parameterIndex, Object JavaDoc x, int targetSqlType)
307                    throws SQLException {
308         dbPstm.setObject(parameterIndex, x, targetSqlType);
309     }
310
311     /**
312     * Implements method in interface java.sql.PreparedStatement
313     * @see java.sql.PreparedStatement#setObject
314     */

315     public void setObject(int parameterIndex, Object JavaDoc x, int targetSqlType,
316                           int scale) throws SQLException {
317         dbPstm.setObject(parameterIndex, x, targetSqlType);
318     }
319
320     /**
321     * Implements method in interface java.sql.PreparedStatement
322     * @see java.sql.PreparedStatement#setRef
323     */

324     public void setRef(int i, Ref x) throws SQLException {
325         dbPstm.setRef(i, x);
326     }
327
328     /**
329     * Implements method in interface java.sql.PreparedStatement
330     * @see java.sql.PreparedStatement#setShort
331     */

332     public void setShort(int parameterIndex, short x) throws SQLException {
333         dbPstm.setShort(parameterIndex, x);
334     }
335
336     /**
337     * Implements method in interface java.sql.PreparedStatement
338     * @see java.sql.PreparedStatement#setString
339     */

340     public void setString(int parameterIndex, String JavaDoc x)
341                    throws SQLException {
342         dbPstm.setString(parameterIndex, x);
343     }
344
345     /**
346     * Implements method in interface java.sql.PreparedStatement
347     * @see java.sql.PreparedStatement#setTime
348     */

349     public void setTime(int parameterIndex, java.sql.Time JavaDoc x)
350                  throws SQLException {
351         dbPstm.setTime(parameterIndex, x);
352     }
353
354     /**
355     * Implements method in interface java.sql.PreparedStatement
356     * @see java.sql.PreparedStatement#setTime
357     */

358     public void setTime(int parameterIndex, java.sql.Time JavaDoc x,
359                         java.util.Calendar JavaDoc cal) throws SQLException {
360         dbPstm.setTime(parameterIndex, x, cal);
361     }
362
363     /**
364     * Implements method in interface java.sql.PreparedStatement
365     * @see java.sql.PreparedStatement#setTimestamp
366     */

367     public void setTimestamp(int parameterIndex, java.sql.Timestamp JavaDoc x)
368                       throws SQLException {
369         dbPstm.setTimestamp(parameterIndex, x);
370     }
371
372     /**
373     * Implements method in interface java.sql.PreparedStatement
374     * @see java.sql.PreparedStatement#setTimestamp
375     */

376     public void setTimestamp(int parameterIndex, java.sql.Timestamp JavaDoc x,
377                              java.util.Calendar JavaDoc cal) throws SQLException {
378         dbPstm.setTimestamp(parameterIndex, x, cal);
379     }
380
381     /**
382     * Implements method in interface java.sql.PreparedStatement
383     * @see java.sql.PreparedStatement#setURL
384     */

385     public void setURL(int parameterIndex, java.net.URL JavaDoc x)
386                 throws SQLException {
387         dbPstm.setURL(parameterIndex, x);
388     }
389
390     /**
391     * Implements method in interface java.sql.PreparedStatement
392     * @see java.sql.PreparedStatement#setUnicodeStream
393     */

394     public void setUnicodeStream(int parameterIndex, java.io.InputStream JavaDoc x,
395                                  int length) throws SQLException {
396         dbPstm.setUnicodeStream(parameterIndex, x, length);
397     }
398 }
Popular Tags