Debian Codegraph @

src/main/org/h2/jdbc/JdbcCallableStatement.java

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