1 | /* |
2 | * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0, |
3 | * and the EPL 1.0 (http://h2database.com/html/license.html). |
4 | * Initial Developer: H2 Group |
5 | */ |
6 | package org.h2.jdbc; |
7 | |
8 | import java.io.InputStream; |
9 | import java.io.Reader; |
10 | import java.math.BigDecimal; |
11 | import java.net.URL; |
12 | import java.sql.Array; |
13 | import java.sql.Blob; |
14 | import java.sql.CallableStatement; |
15 | import java.sql.Clob; |
16 | import java.sql.Date; |
17 | import java.sql.NClob; |
18 | import java.sql.Ref; |
19 | import java.sql.ResultSetMetaData; |
20 | import java.sql.RowId; |
21 | import java.sql.SQLException; |
22 | import java.sql.SQLXML; |
23 | import java.sql.Time; |
24 | import java.sql.Timestamp; |
25 | import java.util.Calendar; |
26 | import java.util.HashMap; |
27 | import java.util.Map; |
28 | |
29 | import org.h2.api.ErrorCode; |
30 | import org.h2.expression.ParameterInterface; |
31 | import org.h2.message.DbException; |
32 | import org.h2.message.TraceObject; |
33 | import org.h2.util.BitField; |
34 | import org.h2.util.New; |
35 | import org.h2.value.ValueNull; |
36 | |
37 | /** |
38 | * Represents a callable statement. |
39 | * |
40 | * @author Sergi Vladykin |
41 | * @author Thomas Mueller |
42 | */ |
43 | public class JdbcCallableStatement extends JdbcPreparedStatement implements |
44 | CallableStatement { |
45 | |
46 | private BitField outParameters; |
47 | private int maxOutParameters; |
48 | private HashMap<String, Integer> namedParameters; |
49 | |
50 | JdbcCallableStatement(JdbcConnection conn, String sql, int id, |
51 | int resultSetType, int resultSetConcurrency) { |
52 | super(conn, sql, id, resultSetType, resultSetConcurrency, false); |
53 | setTrace(session.getTrace(), TraceObject.CALLABLE_STATEMENT, id); |
54 | } |
55 | |
56 | /** |
57 | * Executes a statement (insert, update, delete, create, drop) |
58 | * and returns the update count. |
59 | * If another result set exists for this statement, this will be closed |
60 | * (even if this statement fails). |
61 | * |
62 | * If auto commit is on, this statement will be committed. |
63 | * If the statement is a DDL statement (create, drop, alter) and does not |
64 | * throw an exception, the current transaction (if any) is committed after |
65 | * executing the statement. |
66 | * |
67 | * @return the update count (number of row affected by an insert, update or |
68 | * delete, or 0 if no rows or the statement was a create, drop, |
69 | * commit or rollback) |
70 | * @throws SQLException if this object is closed or invalid |
71 | */ |
72 | @Override |
73 | public int executeUpdate() throws SQLException { |
74 | try { |
75 | checkClosed(); |
76 | if (command.isQuery()) { |
77 | super.executeQuery(); |
78 | return 0; |
79 | } |
80 | return super.executeUpdate(); |
81 | } catch (Exception e) { |
82 | throw logAndConvert(e); |
83 | } |
84 | } |
85 | |
86 | /** |
87 | * Registers the given OUT parameter. |
88 | * |
89 | * @param parameterIndex the parameter index (1, 2, ...) |
90 | * @param sqlType the data type (Types.x) - ignored |
91 | */ |
92 | @Override |
93 | public void registerOutParameter(int parameterIndex, int sqlType) |
94 | throws SQLException { |
95 | registerOutParameter(parameterIndex); |
96 | } |
97 | |
98 | /** |
99 | * Registers the given OUT parameter. |
100 | * |
101 | * @param parameterIndex the parameter index (1, 2, ...) |
102 | * @param sqlType the data type (Types.x) - ignored |
103 | * @param typeName the SQL type name - ignored |
104 | */ |
105 | @Override |
106 | public void registerOutParameter(int parameterIndex, int sqlType, |
107 | String typeName) throws SQLException { |
108 | registerOutParameter(parameterIndex); |
109 | } |
110 | |
111 | /** |
112 | * Registers the given OUT parameter. |
113 | * |
114 | * @param parameterIndex the parameter index (1, 2, ...) |
115 | * @param sqlType the data type (Types.x) |
116 | * @param scale is ignored |
117 | */ |
118 | @Override |
119 | public void registerOutParameter(int parameterIndex, int sqlType, int scale) |
120 | throws SQLException { |
121 | registerOutParameter(parameterIndex); |
122 | } |
123 | |
124 | /** |
125 | * Registers the given OUT parameter. |
126 | * |
127 | * @param parameterName the parameter name |
128 | * @param sqlType the data type (Types.x) - ignored |
129 | * @param typeName the SQL type name - ignored |
130 | */ |
131 | @Override |
132 | public void registerOutParameter(String parameterName, int sqlType, |
133 | String typeName) throws SQLException { |
134 | registerOutParameter(getIndexForName(parameterName), sqlType, typeName); |
135 | } |
136 | |
137 | /** |
138 | * Registers the given OUT parameter. |
139 | * |
140 | * @param parameterName the parameter name |
141 | * @param sqlType the data type (Types.x) - ignored |
142 | * @param scale is ignored |
143 | */ |
144 | @Override |
145 | public void registerOutParameter(String parameterName, int sqlType, |
146 | int scale) throws SQLException { |
147 | registerOutParameter(getIndexForName(parameterName), sqlType, scale); |
148 | } |
149 | |
150 | /** |
151 | * Registers the given OUT parameter. |
152 | * |
153 | * @param parameterName the parameter name |
154 | * @param sqlType the data type (Types.x) - ignored |
155 | */ |
156 | @Override |
157 | public void registerOutParameter(String parameterName, int sqlType) |
158 | throws SQLException { |
159 | registerOutParameter(getIndexForName(parameterName), sqlType); |
160 | } |
161 | |
162 | /** |
163 | * Returns whether the last column accessed was null. |
164 | * |
165 | * @return true if the last column accessed was null |
166 | */ |
167 | @Override |
168 | public boolean wasNull() throws SQLException { |
169 | return getOpenResultSet().wasNull(); |
170 | } |
171 | |
172 | /** |
173 | * [Not supported] |
174 | */ |
175 | @Override |
176 | public URL getURL(int parameterIndex) throws SQLException { |
177 | throw unsupported("url"); |
178 | } |
179 | |
180 | /** |
181 | * Returns the value of the specified column as a String. |
182 | * |
183 | * @param parameterIndex (1,2,...) |
184 | * @return the value |
185 | * @throws SQLException if the column is not found or if this object is |
186 | * closed |
187 | */ |
188 | @Override |
189 | public String getString(int parameterIndex) throws SQLException { |
190 | checkRegistered(parameterIndex); |
191 | return getOpenResultSet().getString(parameterIndex); |
192 | } |
193 | |
194 | /** |
195 | * Returns the value of the specified column as a boolean. |
196 | * |
197 | * @param parameterIndex (1,2,...) |
198 | * @return the value |
199 | * @throws SQLException if the column is not found or if this object is |
200 | * closed |
201 | */ |
202 | @Override |
203 | public boolean getBoolean(int parameterIndex) throws SQLException { |
204 | checkRegistered(parameterIndex); |
205 | return getOpenResultSet().getBoolean(parameterIndex); |
206 | } |
207 | |
208 | /** |
209 | * Returns the value of the specified column as a byte. |
210 | * |
211 | * @param parameterIndex (1,2,...) |
212 | * @return the value |
213 | * @throws SQLException if the column is not found or if this object is |
214 | * closed |
215 | */ |
216 | @Override |
217 | public byte getByte(int parameterIndex) throws SQLException { |
218 | checkRegistered(parameterIndex); |
219 | return getOpenResultSet().getByte(parameterIndex); |
220 | } |
221 | |
222 | /** |
223 | * Returns the value of the specified column as a short. |
224 | * |
225 | * @param parameterIndex (1,2,...) |
226 | * @return the value |
227 | * @throws SQLException if the column is not found or if this object is |
228 | * closed |
229 | */ |
230 | @Override |
231 | public short getShort(int parameterIndex) throws SQLException { |
232 | checkRegistered(parameterIndex); |
233 | return getOpenResultSet().getShort(parameterIndex); |
234 | } |
235 | |
236 | /** |
237 | * Returns the value of the specified column as an int. |
238 | * |
239 | * @param parameterIndex the parameter index (1, 2, ...) |
240 | * @return the value |
241 | * @throws SQLException if the column is not found or if this object is |
242 | * closed |
243 | */ |
244 | @Override |
245 | public int getInt(int parameterIndex) throws SQLException { |
246 | checkRegistered(parameterIndex); |
247 | return getOpenResultSet().getInt(parameterIndex); |
248 | } |
249 | |
250 | /** |
251 | * Returns the value of the specified column as a long. |
252 | * |
253 | * @param parameterIndex the parameter index (1, 2, ...) |
254 | * @return the value |
255 | * @throws SQLException if the column is not found or if this object is |
256 | * closed |
257 | */ |
258 | @Override |
259 | public long getLong(int parameterIndex) throws SQLException { |
260 | checkRegistered(parameterIndex); |
261 | return getOpenResultSet().getLong(parameterIndex); |
262 | } |
263 | |
264 | /** |
265 | * Returns the value of the specified column as a float. |
266 | * |
267 | * @param parameterIndex the parameter index (1, 2, ...) |
268 | * @return the value |
269 | * @throws SQLException if the column is not found or if this object is |
270 | * closed |
271 | */ |
272 | @Override |
273 | public float getFloat(int parameterIndex) throws SQLException { |
274 | checkRegistered(parameterIndex); |
275 | return getOpenResultSet().getFloat(parameterIndex); |
276 | } |
277 | |
278 | /** |
279 | * Returns the value of the specified column as a double. |
280 | * |
281 | * @param parameterIndex the parameter index (1, 2, ...) |
282 | * @return the value |
283 | * @throws SQLException if the column is not found or if this object is |
284 | * closed |
285 | */ |
286 | @Override |
287 | public double getDouble(int parameterIndex) throws SQLException { |
288 | checkRegistered(parameterIndex); |
289 | return getOpenResultSet().getDouble(parameterIndex); |
290 | } |
291 | |
292 | /** |
293 | * Returns the value of the specified column as a BigDecimal. |
294 | * |
295 | * @deprecated use {@link #getBigDecimal(int)} |
296 | * |
297 | * @param parameterIndex the parameter index (1, 2, ...) |
298 | * @param scale is ignored |
299 | * @return the value |
300 | * @throws SQLException if the column is not found or if this object is |
301 | * closed |
302 | */ |
303 | @Override |
304 | public BigDecimal getBigDecimal(int parameterIndex, int scale) |
305 | throws SQLException { |
306 | checkRegistered(parameterIndex); |
307 | return getOpenResultSet().getBigDecimal(parameterIndex, scale); |
308 | } |
309 | |
310 | /** |
311 | * Returns the value of the specified column as a byte array. |
312 | * |
313 | * @param parameterIndex the parameter index (1, 2, ...) |
314 | * @return the value |
315 | * @throws SQLException if the column is not found or if this object is |
316 | * closed |
317 | */ |
318 | @Override |
319 | public byte[] getBytes(int parameterIndex) throws SQLException { |
320 | checkRegistered(parameterIndex); |
321 | return getOpenResultSet().getBytes(parameterIndex); |
322 | } |
323 | |
324 | /** |
325 | * Returns the value of the specified column as a java.sql.Date. |
326 | * |
327 | * @param parameterIndex the parameter index (1, 2, ...) |
328 | * @return the value |
329 | * @throws SQLException if the column is not found or if this object is |
330 | * closed |
331 | */ |
332 | @Override |
333 | public Date getDate(int parameterIndex) throws SQLException { |
334 | checkRegistered(parameterIndex); |
335 | return getOpenResultSet().getDate(parameterIndex); |
336 | } |
337 | |
338 | /** |
339 | * Returns the value of the specified column as a java.sql.Time. |
340 | * |
341 | * @param parameterIndex the parameter index (1, 2, ...) |
342 | * @return the value |
343 | * @throws SQLException if the column is not found or if this object is |
344 | * closed |
345 | */ |
346 | @Override |
347 | public Time getTime(int parameterIndex) throws SQLException { |
348 | checkRegistered(parameterIndex); |
349 | return getOpenResultSet().getTime(parameterIndex); |
350 | } |
351 | |
352 | /** |
353 | * Returns the value of the specified column as a java.sql.Timestamp. |
354 | * |
355 | * @param parameterIndex the parameter index (1, 2, ...) |
356 | * @return the value |
357 | * @throws SQLException if the column is not found or if this object is |
358 | * closed |
359 | */ |
360 | @Override |
361 | public Timestamp getTimestamp(int parameterIndex) throws SQLException { |
362 | checkRegistered(parameterIndex); |
363 | return getOpenResultSet().getTimestamp(parameterIndex); |
364 | } |
365 | |
366 | /** |
367 | * Returns a column value as a Java object. The data is |
368 | * de-serialized into a Java object (on the client side). |
369 | * |
370 | * @param parameterIndex the parameter index (1, 2, ...) |
371 | * @return the value or null |
372 | * @throws SQLException if the column is not found or if this object is |
373 | * closed |
374 | */ |
375 | @Override |
376 | public Object getObject(int parameterIndex) throws SQLException { |
377 | checkRegistered(parameterIndex); |
378 | return getOpenResultSet().getObject(parameterIndex); |
379 | } |
380 | |
381 | /** |
382 | * Returns the value of the specified column as a BigDecimal. |
383 | * |
384 | * @param parameterIndex the parameter index (1, 2, ...) |
385 | * @return the value |
386 | * @throws SQLException if the column is not found or if this object is |
387 | * closed |
388 | */ |
389 | @Override |
390 | public BigDecimal getBigDecimal(int parameterIndex) throws SQLException { |
391 | checkRegistered(parameterIndex); |
392 | return getOpenResultSet().getBigDecimal(parameterIndex); |
393 | } |
394 | |
395 | /** |
396 | * [Not supported] Gets a column as a object using the specified type |
397 | * mapping. |
398 | */ |
399 | @Override |
400 | public Object getObject(int parameterIndex, Map<String, Class<?>> map) |
401 | throws SQLException { |
402 | throw unsupported("map"); |
403 | } |
404 | |
405 | /** |
406 | * [Not supported] Gets a column as a reference. |
407 | */ |
408 | @Override |
409 | public Ref getRef(int parameterIndex) throws SQLException { |
410 | throw unsupported("ref"); |
411 | } |
412 | |
413 | /** |
414 | * Returns the value of the specified column as a Blob. |
415 | * |
416 | * @param parameterIndex the parameter index (1, 2, ...) |
417 | * @return the value |
418 | * @throws SQLException if the column is not found or if this object is |
419 | * closed |
420 | */ |
421 | @Override |
422 | public Blob getBlob(int parameterIndex) throws SQLException { |
423 | checkRegistered(parameterIndex); |
424 | return getOpenResultSet().getBlob(parameterIndex); |
425 | } |
426 | |
427 | /** |
428 | * Returns the value of the specified column as a Clob. |
429 | * |
430 | * @param parameterIndex the parameter index (1, 2, ...) |
431 | * @return the value |
432 | * @throws SQLException if the column is not found or if this object is |
433 | * closed |
434 | */ |
435 | @Override |
436 | public Clob getClob(int parameterIndex) throws SQLException { |
437 | checkRegistered(parameterIndex); |
438 | return getOpenResultSet().getClob(parameterIndex); |
439 | } |
440 | |
441 | /** |
442 | * Returns the value of the specified column as an Array. |
443 | * |
444 | * @param parameterIndex the parameter index (1, 2, ...) |
445 | * @return the value |
446 | * @throws SQLException if the column is not found or if this object is |
447 | * closed |
448 | */ |
449 | @Override |
450 | public Array getArray(int parameterIndex) throws SQLException { |
451 | checkRegistered(parameterIndex); |
452 | return getOpenResultSet().getArray(parameterIndex); |
453 | } |
454 | |
455 | /** |
456 | * Returns the value of the specified column as a java.sql.Date using a |
457 | * specified time zone. |
458 | * |
459 | * @param parameterIndex the parameter index (1, 2, ...) |
460 | * @param cal the calendar |
461 | * @return the value |
462 | * @throws SQLException if the column is not found or if this object is |
463 | * closed |
464 | */ |
465 | @Override |
466 | public Date getDate(int parameterIndex, Calendar cal) throws SQLException { |
467 | checkRegistered(parameterIndex); |
468 | return getOpenResultSet().getDate(parameterIndex, cal); |
469 | } |
470 | |
471 | /** |
472 | * Returns the value of the specified column as a java.sql.Time using a |
473 | * specified time zone. |
474 | * |
475 | * @param parameterIndex the parameter index (1, 2, ...) |
476 | * @param cal the calendar |
477 | * @return the value |
478 | * @throws SQLException if the column is not found or if this object is |
479 | * closed |
480 | */ |
481 | @Override |
482 | public Time getTime(int parameterIndex, Calendar cal) throws SQLException { |
483 | checkRegistered(parameterIndex); |
484 | return getOpenResultSet().getTime(parameterIndex, cal); |
485 | } |
486 | |
487 | /** |
488 | * Returns the value of the specified column as a java.sql.Timestamp using a |
489 | * specified time zone. |
490 | * |
491 | * @param parameterIndex the parameter index (1, 2, ...) |
492 | * @param cal the calendar |
493 | * @return the value |
494 | * @throws SQLException if the column is not found or if this object is |
495 | * closed |
496 | */ |
497 | @Override |
498 | public Timestamp getTimestamp(int parameterIndex, Calendar cal) |
499 | throws SQLException { |
500 | checkRegistered(parameterIndex); |
501 | return getOpenResultSet().getTimestamp(parameterIndex, cal); |
502 | } |
503 | |
504 | /** |
505 | * [Not supported] |
506 | */ |
507 | @Override |
508 | public URL getURL(String parameterName) throws SQLException { |
509 | throw unsupported("url"); |
510 | } |
511 | |
512 | /** |
513 | * Returns the value of the specified column as a java.sql.Timestamp using a |
514 | * specified time zone. |
515 | * |
516 | * @param parameterName the parameter name |
517 | * @param cal the calendar |
518 | * @return the value |
519 | * @throws SQLException if the column is not found or if this object is |
520 | * closed |
521 | */ |
522 | @Override |
523 | public Timestamp getTimestamp(String parameterName, Calendar cal) |
524 | throws SQLException { |
525 | return getTimestamp(getIndexForName(parameterName), cal); |
526 | } |
527 | |
528 | /** |
529 | * Returns the value of the specified column as a java.sql.Time using a |
530 | * specified time zone. |
531 | * |
532 | * @param parameterName the parameter name |
533 | * @param cal the calendar |
534 | * @return the value |
535 | * @throws SQLException if the column is not found or if this object is |
536 | * closed |
537 | */ |
538 | @Override |
539 | public Time getTime(String parameterName, Calendar cal) throws SQLException { |
540 | return getTime(getIndexForName(parameterName), cal); |
541 | } |
542 | |
543 | /** |
544 | * Returns the value of the specified column as a java.sql.Date using a |
545 | * specified time zone. |
546 | * |
547 | * @param parameterName the parameter name |
548 | * @param cal the calendar |
549 | * @return the value |
550 | * @throws SQLException if the column is not found or if this object is |
551 | * closed |
552 | */ |
553 | @Override |
554 | public Date getDate(String parameterName, Calendar cal) throws SQLException { |
555 | return getDate(getIndexForName(parameterName), cal); |
556 | } |
557 | |
558 | /** |
559 | * Returns the value of the specified column as an Array. |
560 | * |
561 | * @param parameterName the parameter name |
562 | * @return the value |
563 | * @throws SQLException if the column is not found or if this object is |
564 | * closed |
565 | */ |
566 | @Override |
567 | public Array getArray(String parameterName) throws SQLException { |
568 | return getArray(getIndexForName(parameterName)); |
569 | } |
570 | |
571 | /** |
572 | * Returns the value of the specified column as a Clob. |
573 | * |
574 | * @param parameterName the parameter name |
575 | * @return the value |
576 | * @throws SQLException if the column is not found or if this object is |
577 | * closed |
578 | */ |
579 | @Override |
580 | public Clob getClob(String parameterName) throws SQLException { |
581 | return getClob(getIndexForName(parameterName)); |
582 | } |
583 | |
584 | /** |
585 | * Returns the value of the specified column as a Blob. |
586 | * |
587 | * @param parameterName the parameter name |
588 | * @return the value |
589 | * @throws SQLException if the column is not found or if this object is |
590 | * closed |
591 | */ |
592 | @Override |
593 | public Blob getBlob(String parameterName) throws SQLException { |
594 | return getBlob(getIndexForName(parameterName)); |
595 | } |
596 | |
597 | /** |
598 | * [Not supported] Gets a column as a reference. |
599 | */ |
600 | @Override |
601 | public Ref getRef(String parameterName) throws SQLException { |
602 | throw unsupported("ref"); |
603 | } |
604 | |
605 | /** |
606 | * [Not supported] Gets a column as a object using the specified type |
607 | * mapping. |
608 | */ |
609 | @Override |
610 | public Object getObject(String parameterName, Map<String, Class<?>> map) |
611 | throws SQLException { |
612 | throw unsupported("map"); |
613 | } |
614 | |
615 | /** |
616 | * Returns the value of the specified column as a BigDecimal. |
617 | * |
618 | * @param parameterName the parameter name |
619 | * @return the value |
620 | * @throws SQLException if the column is not found or if this object is |
621 | * closed |
622 | */ |
623 | @Override |
624 | public BigDecimal getBigDecimal(String parameterName) throws SQLException { |
625 | return getBigDecimal(getIndexForName(parameterName)); |
626 | } |
627 | |
628 | /** |
629 | * Returns a column value as a Java object. The data is |
630 | * de-serialized into a Java object (on the client side). |
631 | * |
632 | * @param parameterName the parameter name |
633 | * @return the value or null |
634 | * @throws SQLException if the column is not found or if this object is |
635 | * closed |
636 | */ |
637 | @Override |
638 | public Object getObject(String parameterName) throws SQLException { |
639 | return getObject(getIndexForName(parameterName)); |
640 | } |
641 | |
642 | /** |
643 | * Returns the value of the specified column as a java.sql.Timestamp. |
644 | * |
645 | * @param parameterName the parameter name |
646 | * @return the value |
647 | * @throws SQLException if the column is not found or if this object is |
648 | * closed |
649 | */ |
650 | @Override |
651 | public Timestamp getTimestamp(String parameterName) throws SQLException { |
652 | return getTimestamp(getIndexForName(parameterName)); |
653 | } |
654 | |
655 | /** |
656 | * Returns the value of the specified column as a java.sql.Time. |
657 | * |
658 | * @param parameterName the parameter name |
659 | * @return the value |
660 | * @throws SQLException if the column is not found or if this object is |
661 | * closed |
662 | */ |
663 | @Override |
664 | public Time getTime(String parameterName) throws SQLException { |
665 | return getTime(getIndexForName(parameterName)); |
666 | } |
667 | |
668 | /** |
669 | * Returns the value of the specified column as a java.sql.Date. |
670 | * |
671 | * @param parameterName the parameter name |
672 | * @return the value |
673 | * @throws SQLException if the column is not found or if this object is |
674 | * closed |
675 | */ |
676 | @Override |
677 | public Date getDate(String parameterName) throws SQLException { |
678 | return getDate(getIndexForName(parameterName)); |
679 | } |
680 | |
681 | /** |
682 | * Returns the value of the specified column as a byte array. |
683 | * |
684 | * @param parameterName the parameter name |
685 | * @return the value |
686 | * @throws SQLException if the column is not found or if this object is |
687 | * closed |
688 | */ |
689 | @Override |
690 | public byte[] getBytes(String parameterName) throws SQLException { |
691 | return getBytes(getIndexForName(parameterName)); |
692 | } |
693 | |
694 | /** |
695 | * Returns the value of the specified column as a double. |
696 | * |
697 | * @param parameterName the parameter name |
698 | * @return the value |
699 | * @throws SQLException if the column is not found or if this object is |
700 | * closed |
701 | */ |
702 | @Override |
703 | public double getDouble(String parameterName) throws SQLException { |
704 | return getDouble(getIndexForName(parameterName)); |
705 | } |
706 | |
707 | /** |
708 | * Returns the value of the specified column as a float. |
709 | * |
710 | * @param parameterName the parameter name |
711 | * @return the value |
712 | * @throws SQLException if the column is not found or if this object is |
713 | * closed |
714 | */ |
715 | @Override |
716 | public float getFloat(String parameterName) throws SQLException { |
717 | return getFloat(getIndexForName(parameterName)); |
718 | } |
719 | |
720 | /** |
721 | * Returns the value of the specified column as a long. |
722 | * |
723 | * @param parameterName the parameter name |
724 | * @return the value |
725 | * @throws SQLException if the column is not found or if this object is |
726 | * closed |
727 | */ |
728 | @Override |
729 | public long getLong(String parameterName) throws SQLException { |
730 | return getLong(getIndexForName(parameterName)); |
731 | } |
732 | |
733 | /** |
734 | * Returns the value of the specified column as an int. |
735 | * |
736 | * @param parameterName the parameter name |
737 | * @return the value |
738 | * @throws SQLException if the column is not found or if this object is |
739 | * closed |
740 | */ |
741 | @Override |
742 | public int getInt(String parameterName) throws SQLException { |
743 | return getInt(getIndexForName(parameterName)); |
744 | } |
745 | |
746 | /** |
747 | * Returns the value of the specified column as a short. |
748 | * |
749 | * @param parameterName the parameter name |
750 | * @return the value |
751 | * @throws SQLException if the column is not found or if this object is |
752 | * closed |
753 | */ |
754 | @Override |
755 | public short getShort(String parameterName) throws SQLException { |
756 | return getShort(getIndexForName(parameterName)); |
757 | } |
758 | |
759 | /** |
760 | * Returns the value of the specified column as a byte. |
761 | * |
762 | * @param parameterName the parameter name |
763 | * @return the value |
764 | * @throws SQLException if the column is not found or if this object is |
765 | * closed |
766 | */ |
767 | @Override |
768 | public byte getByte(String parameterName) throws SQLException { |
769 | return getByte(getIndexForName(parameterName)); |
770 | } |
771 | |
772 | /** |
773 | * Returns the value of the specified column as a boolean. |
774 | * |
775 | * @param parameterName the parameter name |
776 | * @return the value |
777 | * @throws SQLException if the column is not found or if this object is |
778 | * closed |
779 | */ |
780 | @Override |
781 | public boolean getBoolean(String parameterName) throws SQLException { |
782 | return getBoolean(getIndexForName(parameterName)); |
783 | } |
784 | |
785 | /** |
786 | * Returns the value of the specified column as a String. |
787 | * |
788 | * @param parameterName the parameter name |
789 | * @return the value |
790 | * @throws SQLException if the column is not found or if this object is |
791 | * closed |
792 | */ |
793 | @Override |
794 | public String getString(String parameterName) throws SQLException { |
795 | return getString(getIndexForName(parameterName)); |
796 | } |
797 | |
798 | /** |
799 | * [Not supported] Returns the value of the specified column as a row id. |
800 | * |
801 | * @param parameterIndex the parameter index (1, 2, ...) |
802 | */ |
803 | @Override |
804 | public RowId getRowId(int parameterIndex) throws SQLException { |
805 | throw unsupported("rowId"); |
806 | } |
807 | |
808 | /** |
809 | * [Not supported] Returns the value of the specified column as a row id. |
810 | * |
811 | * @param parameterName the parameter name |
812 | */ |
813 | @Override |
814 | public RowId getRowId(String parameterName) throws SQLException { |
815 | throw unsupported("rowId"); |
816 | } |
817 | |
818 | /** |
819 | * Returns the value of the specified column as a Clob. |
820 | * |
821 | * @param parameterIndex the parameter index (1, 2, ...) |
822 | * @return the value |
823 | * @throws SQLException if the column is not found or if this object is |
824 | * closed |
825 | */ |
826 | @Override |
827 | public NClob getNClob(int parameterIndex) throws SQLException { |
828 | checkRegistered(parameterIndex); |
829 | return getOpenResultSet().getNClob(parameterIndex); |
830 | } |
831 | |
832 | /** |
833 | * Returns the value of the specified column as a Clob. |
834 | * |
835 | * @param parameterName the parameter name |
836 | * @return the value |
837 | * @throws SQLException if the column is not found or if this object is |
838 | * closed |
839 | */ |
840 | @Override |
841 | public NClob getNClob(String parameterName) throws SQLException { |
842 | return getNClob(getIndexForName(parameterName)); |
843 | } |
844 | |
845 | /** |
846 | * [Not supported] Returns the value of the specified column as a SQLXML |
847 | * object. |
848 | */ |
849 | @Override |
850 | public SQLXML getSQLXML(int parameterIndex) throws SQLException { |
851 | throw unsupported("SQLXML"); |
852 | } |
853 | |
854 | /** |
855 | * [Not supported] Returns the value of the specified column as a SQLXML |
856 | * object. |
857 | */ |
858 | @Override |
859 | public SQLXML getSQLXML(String parameterName) throws SQLException { |
860 | throw unsupported("SQLXML"); |
861 | } |
862 | |
863 | /** |
864 | * Returns the value of the specified column as a String. |
865 | * |
866 | * @param parameterIndex the parameter index (1, 2, ...) |
867 | * @return the value |
868 | * @throws SQLException if the column is not found or if this object is |
869 | * closed |
870 | */ |
871 | @Override |
872 | public String getNString(int parameterIndex) throws SQLException { |
873 | checkRegistered(parameterIndex); |
874 | return getOpenResultSet().getNString(parameterIndex); |
875 | } |
876 | |
877 | /** |
878 | * Returns the value of the specified column as a String. |
879 | * |
880 | * @param parameterName the parameter name |
881 | * @return the value |
882 | * @throws SQLException if the column is not found or if this object is |
883 | * closed |
884 | */ |
885 | @Override |
886 | public String getNString(String parameterName) throws SQLException { |
887 | return getNString(getIndexForName(parameterName)); |
888 | } |
889 | |
890 | /** |
891 | * Returns the value of the specified column as a reader. |
892 | * |
893 | * @param parameterIndex the parameter index (1, 2, ...) |
894 | * @return the value |
895 | * @throws SQLException if the column is not found or if this object is |
896 | * closed |
897 | */ |
898 | @Override |
899 | public Reader getNCharacterStream(int parameterIndex) |
900 | throws SQLException { |
901 | checkRegistered(parameterIndex); |
902 | return getOpenResultSet().getNCharacterStream(parameterIndex); |
903 | } |
904 | |
905 | /** |
906 | * Returns the value of the specified column as a reader. |
907 | * |
908 | * @param parameterName the parameter name |
909 | * @return the value |
910 | * @throws SQLException if the column is not found or if this object is |
911 | * closed |
912 | */ |
913 | @Override |
914 | public Reader getNCharacterStream(String parameterName) |
915 | throws SQLException { |
916 | return getNCharacterStream(getIndexForName(parameterName)); |
917 | } |
918 | |
919 | /** |
920 | * Returns the value of the specified column as a reader. |
921 | * |
922 | * @param parameterIndex the parameter index (1, 2, ...) |
923 | * @return the value |
924 | * @throws SQLException if the column is not found or if this object is |
925 | * closed |
926 | */ |
927 | @Override |
928 | public Reader getCharacterStream(int parameterIndex) |
929 | throws SQLException { |
930 | checkRegistered(parameterIndex); |
931 | return getOpenResultSet().getCharacterStream(parameterIndex); |
932 | } |
933 | |
934 | /** |
935 | * Returns the value of the specified column as a reader. |
936 | * |
937 | * @param parameterName the parameter name |
938 | * @return the value |
939 | * @throws SQLException if the column is not found or if this object is |
940 | * closed |
941 | */ |
942 | @Override |
943 | public Reader getCharacterStream(String parameterName) |
944 | throws SQLException { |
945 | return getCharacterStream(getIndexForName(parameterName)); |
946 | } |
947 | |
948 | // ============================================================= |
949 | |
950 | /** |
951 | * Sets a parameter to null. |
952 | * |
953 | * @param parameterName the parameter name |
954 | * @param sqlType the data type (Types.x) |
955 | * @param typeName this parameter is ignored |
956 | * @throws SQLException if this object is closed |
957 | */ |
958 | @Override |
959 | public void setNull(String parameterName, int sqlType, String typeName) |
960 | throws SQLException { |
961 | setNull(getIndexForName(parameterName), sqlType, typeName); |
962 | } |
963 | |
964 | /** |
965 | * Sets a parameter to null. |
966 | * |
967 | * @param parameterName the parameter name |
968 | * @param sqlType the data type (Types.x) |
969 | * @throws SQLException if this object is closed |
970 | */ |
971 | @Override |
972 | public void setNull(String parameterName, int sqlType) throws SQLException { |
973 | setNull(getIndexForName(parameterName), sqlType); |
974 | } |
975 | |
976 | /** |
977 | * Sets the timestamp using a specified time zone. The value will be |
978 | * converted to the local time zone. |
979 | * |
980 | * @param parameterName the parameter name |
981 | * @param x the value |
982 | * @param cal the calendar |
983 | * @throws SQLException if this object is closed |
984 | */ |
985 | @Override |
986 | public void setTimestamp(String parameterName, Timestamp x, Calendar cal) |
987 | throws SQLException { |
988 | setTimestamp(getIndexForName(parameterName), x, cal); |
989 | } |
990 | |
991 | /** |
992 | * Sets the time using a specified time zone. The value will be converted to |
993 | * the local time zone. |
994 | * |
995 | * @param parameterName the parameter name |
996 | * @param x the value |
997 | * @param cal the calendar |
998 | * @throws SQLException if this object is closed |
999 | */ |
1000 | @Override |
1001 | public void setTime(String parameterName, Time x, Calendar cal) |
1002 | throws SQLException { |
1003 | setTime(getIndexForName(parameterName), x, cal); |
1004 | } |
1005 | |
1006 | /** |
1007 | * Sets the date using a specified time zone. The value will be converted to |
1008 | * the local time zone. |
1009 | * |
1010 | * @param parameterName the parameter name |
1011 | * @param x the value |
1012 | * @param cal the calendar |
1013 | * @throws SQLException if this object is closed |
1014 | */ |
1015 | @Override |
1016 | public void setDate(String parameterName, Date x, Calendar cal) |
1017 | throws SQLException { |
1018 | setDate(getIndexForName(parameterName), x, cal); |
1019 | } |
1020 | |
1021 | /** |
1022 | * Sets the value of a parameter as a character stream. |
1023 | * This method does not close the reader. |
1024 | * The reader may be closed after executing the statement. |
1025 | * |
1026 | * @param parameterName the parameter name |
1027 | * @param x the value |
1028 | * @param length the maximum number of characters |
1029 | * @throws SQLException if this object is closed |
1030 | */ |
1031 | @Override |
1032 | public void setCharacterStream(String parameterName, Reader x, int length) |
1033 | throws SQLException { |
1034 | setCharacterStream(getIndexForName(parameterName), x, length); |
1035 | } |
1036 | |
1037 | /** |
1038 | * Sets the value of a parameter. |
1039 | * Objects of unknown classes are serialized (on the client side). |
1040 | * |
1041 | * @param parameterName the parameter name |
1042 | * @param x the value |
1043 | * @throws SQLException if this object is closed |
1044 | */ |
1045 | @Override |
1046 | public void setObject(String parameterName, Object x) throws SQLException { |
1047 | setObject(getIndexForName(parameterName), x); |
1048 | } |
1049 | |
1050 | /** |
1051 | * Sets the value of a parameter. The object is converted, if required, to |
1052 | * the specified data type before sending to the database. |
1053 | * Objects of unknown classes are serialized (on the client side). |
1054 | * |
1055 | * @param parameterName the parameter name |
1056 | * @param x the value, null is allowed |
1057 | * @param targetSqlType the type as defined in java.sql.Types |
1058 | * @throws SQLException if this object is closed |
1059 | */ |
1060 | @Override |
1061 | public void setObject(String parameterName, Object x, int targetSqlType) |
1062 | throws SQLException { |
1063 | setObject(getIndexForName(parameterName), x, targetSqlType); |
1064 | } |
1065 | |
1066 | /** |
1067 | * Sets the value of a parameter. The object is converted, if required, to |
1068 | * the specified data type before sending to the database. |
1069 | * Objects of unknown classes are serialized (on the client side). |
1070 | * |
1071 | * @param parameterName the parameter name |
1072 | * @param x the value, null is allowed |
1073 | * @param targetSqlType the type as defined in java.sql.Types |
1074 | * @param scale is ignored |
1075 | * @throws SQLException if this object is closed |
1076 | */ |
1077 | @Override |
1078 | public void setObject(String parameterName, Object x, int targetSqlType, |
1079 | int scale) throws SQLException { |
1080 | setObject(getIndexForName(parameterName), x, targetSqlType, scale); |
1081 | } |
1082 | |
1083 | /** |
1084 | * Sets the value of a parameter as an input stream. |
1085 | * This method does not close the stream. |
1086 | * The stream may be closed after executing the statement. |
1087 | * |
1088 | * @param parameterName the parameter name |
1089 | * @param x the value |
1090 | * @param length the maximum number of bytes |
1091 | * @throws SQLException if this object is closed |
1092 | */ |
1093 | @Override |
1094 | public void setBinaryStream(String parameterName, InputStream x, int length) |
1095 | throws SQLException { |
1096 | setBinaryStream(getIndexForName(parameterName), x, length); |
1097 | } |
1098 | |
1099 | /** |
1100 | * Sets the value of a parameter as an ASCII stream. |
1101 | * This method does not close the stream. |
1102 | * The stream may be closed after executing the statement. |
1103 | * |
1104 | * @param parameterName the parameter name |
1105 | * @param x the value |
1106 | * @param length the maximum number of bytes |
1107 | * @throws SQLException if this object is closed |
1108 | */ |
1109 | @Override |
1110 | public void setAsciiStream(String parameterName, |
1111 | InputStream x, long length) throws SQLException { |
1112 | setAsciiStream(getIndexForName(parameterName), x, length); |
1113 | } |
1114 | |
1115 | /** |
1116 | * Sets the value of a parameter. |
1117 | * |
1118 | * @param parameterName the parameter name |
1119 | * @param x the value |
1120 | * @throws SQLException if this object is closed |
1121 | */ |
1122 | @Override |
1123 | public void setTimestamp(String parameterName, Timestamp x) |
1124 | throws SQLException { |
1125 | setTimestamp(getIndexForName(parameterName), x); |
1126 | } |
1127 | |
1128 | /** |
1129 | * Sets the time using a specified time zone. |
1130 | * |
1131 | * @param parameterName the parameter name |
1132 | * @param x the value |
1133 | * @throws SQLException if this object is closed |
1134 | */ |
1135 | @Override |
1136 | public void setTime(String parameterName, Time x) throws SQLException { |
1137 | setTime(getIndexForName(parameterName), x); |
1138 | } |
1139 | |
1140 | /** |
1141 | * Sets the value of a parameter. |
1142 | * |
1143 | * @param parameterName the parameter name |
1144 | * @param x the value |
1145 | * @throws SQLException if this object is closed |
1146 | */ |
1147 | @Override |
1148 | public void setDate(String parameterName, Date x) throws SQLException { |
1149 | setDate(getIndexForName(parameterName), x); |
1150 | } |
1151 | |
1152 | /** |
1153 | * Sets the value of a parameter as a byte array. |
1154 | * |
1155 | * @param parameterName the parameter name |
1156 | * @param x the value |
1157 | * @throws SQLException if this object is closed |
1158 | */ |
1159 | @Override |
1160 | public void setBytes(String parameterName, byte[] x) throws SQLException { |
1161 | setBytes(getIndexForName(parameterName), x); |
1162 | } |
1163 | |
1164 | /** |
1165 | * Sets the value of a parameter. |
1166 | * |
1167 | * @param parameterName the parameter name |
1168 | * @param x the value |
1169 | * @throws SQLException if this object is closed |
1170 | */ |
1171 | @Override |
1172 | public void setString(String parameterName, String x) throws SQLException { |
1173 | setString(getIndexForName(parameterName), x); |
1174 | } |
1175 | |
1176 | /** |
1177 | * Sets the value of a parameter. |
1178 | * |
1179 | * @param parameterName the parameter name |
1180 | * @param x the value |
1181 | * @throws SQLException if this object is closed |
1182 | */ |
1183 | @Override |
1184 | public void setBigDecimal(String parameterName, BigDecimal x) |
1185 | throws SQLException { |
1186 | setBigDecimal(getIndexForName(parameterName), x); |
1187 | } |
1188 | |
1189 | /** |
1190 | * Sets the value of a parameter. |
1191 | * |
1192 | * @param parameterName the parameter name |
1193 | * @param x the value |
1194 | * @throws SQLException if this object is closed |
1195 | */ |
1196 | @Override |
1197 | public void setDouble(String parameterName, double x) throws SQLException { |
1198 | setDouble(getIndexForName(parameterName), x); |
1199 | } |
1200 | |
1201 | /** |
1202 | * Sets the value of a parameter. |
1203 | * |
1204 | * @param parameterName the parameter name |
1205 | * @param x the value |
1206 | * @throws SQLException if this object is closed |
1207 | */ |
1208 | @Override |
1209 | public void setFloat(String parameterName, float x) throws SQLException { |
1210 | setFloat(getIndexForName(parameterName), x); |
1211 | } |
1212 | |
1213 | /** |
1214 | * Sets the value of a parameter. |
1215 | * |
1216 | * @param parameterName the parameter name |
1217 | * @param x the value |
1218 | * @throws SQLException if this object is closed |
1219 | */ |
1220 | @Override |
1221 | public void setLong(String parameterName, long x) throws SQLException { |
1222 | setLong(getIndexForName(parameterName), x); |
1223 | } |
1224 | |
1225 | /** |
1226 | * Sets the value of a parameter. |
1227 | * |
1228 | * @param parameterName the parameter name |
1229 | * @param x the value |
1230 | * @throws SQLException if this object is closed |
1231 | */ |
1232 | @Override |
1233 | public void setInt(String parameterName, int x) throws SQLException { |
1234 | setInt(getIndexForName(parameterName), x); |
1235 | } |
1236 | |
1237 | /** |
1238 | * Sets the value of a parameter. |
1239 | * |
1240 | * @param parameterName the parameter name |
1241 | * @param x the value |
1242 | * @throws SQLException if this object is closed |
1243 | */ |
1244 | @Override |
1245 | public void setShort(String parameterName, short x) throws SQLException { |
1246 | setShort(getIndexForName(parameterName), x); |
1247 | } |
1248 | |
1249 | /** |
1250 | * Sets the value of a parameter. |
1251 | * |
1252 | * @param parameterName the parameter name |
1253 | * @param x the value |
1254 | * @throws SQLException if this object is closed |
1255 | */ |
1256 | @Override |
1257 | public void setByte(String parameterName, byte x) throws SQLException { |
1258 | setByte(getIndexForName(parameterName), x); |
1259 | } |
1260 | |
1261 | /** |
1262 | * Sets the value of a parameter. |
1263 | * |
1264 | * @param parameterName the parameter name |
1265 | * @param x the value |
1266 | * @throws SQLException if this object is closed |
1267 | */ |
1268 | @Override |
1269 | public void setBoolean(String parameterName, boolean x) throws SQLException { |
1270 | setBoolean(getIndexForName(parameterName), x); |
1271 | } |
1272 | |
1273 | /** |
1274 | * [Not supported] |
1275 | */ |
1276 | @Override |
1277 | public void setURL(String parameterName, URL val) throws SQLException { |
1278 | throw unsupported("url"); |
1279 | } |
1280 | |
1281 | /** |
1282 | * [Not supported] Sets the value of a parameter as a row id. |
1283 | */ |
1284 | @Override |
1285 | public void setRowId(String parameterName, RowId x) |
1286 | throws SQLException { |
1287 | throw unsupported("rowId"); |
1288 | } |
1289 | |
1290 | /** |
1291 | * Sets the value of a parameter. |
1292 | * |
1293 | * @param parameterName the parameter name |
1294 | * @param x the value |
1295 | * @throws SQLException if this object is closed |
1296 | */ |
1297 | @Override |
1298 | public void setNString(String parameterName, String x) |
1299 | throws SQLException { |
1300 | setNString(getIndexForName(parameterName), x); |
1301 | } |
1302 | |
1303 | /** |
1304 | * Sets the value of a parameter as a character stream. |
1305 | * This method does not close the reader. |
1306 | * The reader may be closed after executing the statement. |
1307 | * |
1308 | * @param parameterName the parameter name |
1309 | * @param x the value |
1310 | * @param length the maximum number of characters |
1311 | * @throws SQLException if this object is closed |
1312 | */ |
1313 | @Override |
1314 | public void setNCharacterStream(String parameterName, |
1315 | Reader x, long length) throws SQLException { |
1316 | setNCharacterStream(getIndexForName(parameterName), x, length); |
1317 | } |
1318 | |
1319 | /** |
1320 | * Sets the value of a parameter as a Clob. |
1321 | * |
1322 | * @param parameterName the parameter name |
1323 | * @param x the value |
1324 | * @throws SQLException if this object is closed |
1325 | */ |
1326 | @Override |
1327 | public void setNClob(String parameterName, NClob x) |
1328 | throws SQLException { |
1329 | setNClob(getIndexForName(parameterName), x); |
1330 | } |
1331 | |
1332 | /** |
1333 | * Sets the value of a parameter as a Clob. |
1334 | * This method does not close the reader. |
1335 | * The reader may be closed after executing the statement. |
1336 | * |
1337 | * @param parameterName the parameter name |
1338 | * @param x the value |
1339 | * @param length the maximum number of characters |
1340 | * @throws SQLException if this object is closed |
1341 | */ |
1342 | @Override |
1343 | public void setClob(String parameterName, Reader x, |
1344 | long length) throws SQLException { |
1345 | setClob(getIndexForName(parameterName), x, length); |
1346 | } |
1347 | |
1348 | /** |
1349 | * Sets the value of a parameter as a Blob. |
1350 | * This method does not close the stream. |
1351 | * The stream may be closed after executing the statement. |
1352 | * |
1353 | * @param parameterName the parameter name |
1354 | * @param x the value |
1355 | * @param length the maximum number of bytes |
1356 | * @throws SQLException if this object is closed |
1357 | */ |
1358 | @Override |
1359 | public void setBlob(String parameterName, InputStream x, |
1360 | long length) throws SQLException { |
1361 | setBlob(getIndexForName(parameterName), x, length); |
1362 | } |
1363 | |
1364 | /** |
1365 | * Sets the value of a parameter as a Clob. |
1366 | * This method does not close the reader. |
1367 | * The reader may be closed after executing the statement. |
1368 | * |
1369 | * @param parameterName the parameter name |
1370 | * @param x the value |
1371 | * @param length the maximum number of characters |
1372 | * @throws SQLException if this object is closed |
1373 | */ |
1374 | @Override |
1375 | public void setNClob(String parameterName, Reader x, |
1376 | long length) throws SQLException { |
1377 | setNClob(getIndexForName(parameterName), x, length); |
1378 | } |
1379 | |
1380 | /** |
1381 | * Sets the value of a parameter as a Blob. |
1382 | * |
1383 | * @param parameterName the parameter name |
1384 | * @param x the value |
1385 | * @throws SQLException if this object is closed |
1386 | */ |
1387 | @Override |
1388 | public void setBlob(String parameterName, Blob x) |
1389 | throws SQLException { |
1390 | setBlob(getIndexForName(parameterName), x); |
1391 | } |
1392 | |
1393 | /** |
1394 | * Sets the value of a parameter as a Clob. |
1395 | * |
1396 | * @param parameterName the parameter name |
1397 | * @param x the value |
1398 | * @throws SQLException if this object is closed |
1399 | */ |
1400 | @Override |
1401 | public void setClob(String parameterName, Clob x) throws SQLException { |
1402 | setClob(getIndexForName(parameterName), x); |
1403 | } |
1404 | |
1405 | /** |
1406 | * Sets the value of a parameter as an ASCII stream. |
1407 | * This method does not close the stream. |
1408 | * The stream may be closed after executing the statement. |
1409 | * |
1410 | * @param parameterName the parameter name |
1411 | * @param x the value |
1412 | * @throws SQLException if this object is closed |
1413 | */ |
1414 | @Override |
1415 | public void setAsciiStream(String parameterName, InputStream x) |
1416 | throws SQLException { |
1417 | setAsciiStream(getIndexForName(parameterName), x); |
1418 | } |
1419 | |
1420 | /** |
1421 | * Sets the value of a parameter as an ASCII stream. |
1422 | * This method does not close the stream. |
1423 | * The stream may be closed after executing the statement. |
1424 | * |
1425 | * @param parameterName the parameter name |
1426 | * @param x the value |
1427 | * @param length the maximum number of bytes |
1428 | * @throws SQLException if this object is closed |
1429 | */ |
1430 | @Override |
1431 | public void setAsciiStream(String parameterName, |
1432 | InputStream x, int length) throws SQLException { |
1433 | setAsciiStream(getIndexForName(parameterName), x, length); |
1434 | } |
1435 | |
1436 | /** |
1437 | * Sets the value of a parameter as an input stream. |
1438 | * This method does not close the stream. |
1439 | * The stream may be closed after executing the statement. |
1440 | * |
1441 | * @param parameterName the parameter name |
1442 | * @param x the value |
1443 | * @throws SQLException if this object is closed |
1444 | */ |
1445 | @Override |
1446 | public void setBinaryStream(String parameterName, |
1447 | InputStream x) throws SQLException { |
1448 | setBinaryStream(getIndexForName(parameterName), x); |
1449 | } |
1450 | |
1451 | /** |
1452 | * Sets the value of a parameter as an input stream. |
1453 | * This method does not close the stream. |
1454 | * The stream may be closed after executing the statement. |
1455 | * |
1456 | * @param parameterName the parameter name |
1457 | * @param x the value |
1458 | * @param length the maximum number of bytes |
1459 | * @throws SQLException if this object is closed |
1460 | */ |
1461 | @Override |
1462 | public void setBinaryStream(String parameterName, |
1463 | InputStream x, long length) throws SQLException { |
1464 | setBinaryStream(getIndexForName(parameterName), x, length); |
1465 | } |
1466 | |
1467 | /** |
1468 | * Sets the value of a parameter as a Blob. |
1469 | * This method does not close the stream. |
1470 | * The stream may be closed after executing the statement. |
1471 | * |
1472 | * @param parameterName the parameter name |
1473 | * @param x the value |
1474 | * @throws SQLException if this object is closed |
1475 | */ |
1476 | @Override |
1477 | public void setBlob(String parameterName, InputStream x) |
1478 | throws SQLException { |
1479 | setBlob(getIndexForName(parameterName), x); |
1480 | } |
1481 | |
1482 | /** |
1483 | * Sets the value of a parameter as a character stream. |
1484 | * This method does not close the reader. |
1485 | * The reader may be closed after executing the statement. |
1486 | * |
1487 | * @param parameterName the parameter name |
1488 | * @param x the value |
1489 | * @throws SQLException if this object is closed |
1490 | */ |
1491 | @Override |
1492 | public void setCharacterStream(String parameterName, Reader x) |
1493 | throws SQLException { |
1494 | setCharacterStream(getIndexForName(parameterName), x); |
1495 | } |
1496 | |
1497 | /** |
1498 | * Sets the value of a parameter as a character stream. |
1499 | * This method does not close the reader. |
1500 | * The reader may be closed after executing the statement. |
1501 | * |
1502 | * @param parameterName the parameter name |
1503 | * @param x the value |
1504 | * @param length the maximum number of characters |
1505 | * @throws SQLException if this object is closed |
1506 | */ |
1507 | @Override |
1508 | public void setCharacterStream(String parameterName, |
1509 | Reader x, long length) throws SQLException { |
1510 | setCharacterStream(getIndexForName(parameterName), x, length); |
1511 | } |
1512 | |
1513 | /** |
1514 | * Sets the value of a parameter as a character stream. |
1515 | * This method does not close the reader. |
1516 | * The reader may be closed after executing the statement. |
1517 | * |
1518 | * @param parameterName the parameter name |
1519 | * @param x the value |
1520 | * @throws SQLException if this object is closed |
1521 | */ |
1522 | @Override |
1523 | public void setClob(String parameterName, Reader x) throws SQLException { |
1524 | setClob(getIndexForName(parameterName), x); |
1525 | } |
1526 | |
1527 | /** |
1528 | * Sets the value of a parameter as a character stream. |
1529 | * This method does not close the reader. |
1530 | * The reader may be closed after executing the statement. |
1531 | * |
1532 | * @param parameterName the parameter name |
1533 | * @param x the value |
1534 | * @throws SQLException if this object is closed |
1535 | */ |
1536 | @Override |
1537 | public void setNCharacterStream(String parameterName, Reader x) |
1538 | throws SQLException { |
1539 | setNCharacterStream(getIndexForName(parameterName), x); |
1540 | } |
1541 | |
1542 | /** |
1543 | * Sets the value of a parameter as a Clob. |
1544 | * This method does not close the reader. |
1545 | * The reader may be closed after executing the statement. |
1546 | * |
1547 | * @param parameterName the parameter name |
1548 | * @param x the value |
1549 | * @throws SQLException if this object is closed |
1550 | */ |
1551 | @Override |
1552 | public void setNClob(String parameterName, Reader x) |
1553 | throws SQLException { |
1554 | setNClob(getIndexForName(parameterName), x); |
1555 | } |
1556 | |
1557 | /** |
1558 | * [Not supported] Sets the value of a parameter as a SQLXML object. |
1559 | */ |
1560 | @Override |
1561 | public void setSQLXML(String parameterName, SQLXML x) |
1562 | throws SQLException { |
1563 | throw unsupported("SQLXML"); |
1564 | } |
1565 | |
1566 | /** |
1567 | * [Not supported] |
1568 | * |
1569 | * @param parameterIndex the parameter index (1, 2, ...) |
1570 | * @param type the class of the returned value |
1571 | */ |
1572 | //## Java 1.7 ## |
1573 | @Override |
1574 | public <T> T getObject(int parameterIndex, Class<T> type) { |
1575 | return null; |
1576 | } |
1577 | //*/ |
1578 | |
1579 | /** |
1580 | * [Not supported] |
1581 | * |
1582 | * @param parameterName the parameter name |
1583 | * @param type the class of the returned value |
1584 | */ |
1585 | //## Java 1.7 ## |
1586 | @Override |
1587 | public <T> T getObject(String parameterName, Class<T> type) { |
1588 | return null; |
1589 | } |
1590 | //*/ |
1591 | |
1592 | private ResultSetMetaData getCheckedMetaData() throws SQLException { |
1593 | ResultSetMetaData meta = getMetaData(); |
1594 | if (meta == null) { |
1595 | throw DbException.getUnsupportedException( |
1596 | "Supported only for calling stored procedures"); |
1597 | } |
1598 | return meta; |
1599 | } |
1600 | |
1601 | private void checkIndexBounds(int parameterIndex) { |
1602 | checkClosed(); |
1603 | if (parameterIndex < 1 || parameterIndex > maxOutParameters) { |
1604 | throw DbException.getInvalidValueException("parameterIndex", parameterIndex); |
1605 | } |
1606 | } |
1607 | |
1608 | private void registerOutParameter(int parameterIndex) throws SQLException { |
1609 | try { |
1610 | checkClosed(); |
1611 | if (outParameters == null) { |
1612 | maxOutParameters = Math.min( |
1613 | getParameterMetaData().getParameterCount(), |
1614 | getCheckedMetaData().getColumnCount()); |
1615 | outParameters = new BitField(); |
1616 | } |
1617 | checkIndexBounds(parameterIndex); |
1618 | ParameterInterface param = command.getParameters().get(--parameterIndex); |
1619 | if (!param.isValueSet()) { |
1620 | param.setValue(ValueNull.INSTANCE, false); |
1621 | } |
1622 | outParameters.set(parameterIndex); |
1623 | } catch (Exception e) { |
1624 | throw logAndConvert(e); |
1625 | } |
1626 | } |
1627 | |
1628 | private void checkRegistered(int parameterIndex) throws SQLException { |
1629 | try { |
1630 | checkIndexBounds(parameterIndex); |
1631 | if (!outParameters.get(parameterIndex - 1)) { |
1632 | throw DbException.getInvalidValueException("parameterIndex", parameterIndex); |
1633 | } |
1634 | } catch (Exception e) { |
1635 | throw logAndConvert(e); |
1636 | } |
1637 | } |
1638 | |
1639 | private int getIndexForName(String parameterName) throws SQLException { |
1640 | try { |
1641 | checkClosed(); |
1642 | if (namedParameters == null) { |
1643 | ResultSetMetaData meta = getCheckedMetaData(); |
1644 | int columnCount = meta.getColumnCount(); |
1645 | HashMap<String, Integer> map = New.hashMap(columnCount); |
1646 | for (int i = 1; i <= columnCount; i++) { |
1647 | map.put(meta.getColumnLabel(i), i); |
1648 | } |
1649 | namedParameters = map; |
1650 | } |
1651 | Integer index = namedParameters.get(parameterName); |
1652 | if (index == null) { |
1653 | throw DbException.getInvalidValueException("parameterName", parameterName); |
1654 | } |
1655 | return index; |
1656 | } catch (Exception e) { |
1657 | throw logAndConvert(e); |
1658 | } |
1659 | } |
1660 | |
1661 | private JdbcResultSet getOpenResultSet() throws SQLException { |
1662 | try { |
1663 | checkClosed(); |
1664 | if (resultSet == null) { |
1665 | throw DbException.get(ErrorCode.NO_DATA_AVAILABLE); |
1666 | } |
1667 | if (resultSet.isBeforeFirst()) { |
1668 | resultSet.next(); |
1669 | } |
1670 | return resultSet; |
1671 | } catch (Exception e) { |
1672 | throw logAndConvert(e); |
1673 | } |
1674 | } |
1675 | |
1676 | } |