File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\jdbc\JdbcPreparedStatement.java.html

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