1 5 package org.h2.jdbc; 6 7 import java.io.InputStream ; 8 import java.io.Reader ; 9 import java.math.BigDecimal ; 10 import java.net.URL ; 11 import java.sql.Array ; 12 import java.sql.Blob ; 13 import java.sql.Clob ; 14 import java.sql.ParameterMetaData ; 16 import java.sql.Statement ; 17 import java.sql.PreparedStatement ; 19 import java.sql.Ref ; 20 import java.sql.ResultSet ; 21 import java.sql.ResultSetMetaData ; 22 import java.sql.SQLException ; 23 import java.util.Calendar ; 24 25 import org.h2.command.CommandInterface; 26 import org.h2.engine.SessionInterface; 27 import org.h2.expression.ParameterInterface; 28 import org.h2.message.Message; 29 import org.h2.message.TraceObject; 30 import org.h2.result.ResultInterface; 31 import org.h2.util.DateTimeUtils; 32 import org.h2.util.IOUtils; 33 import org.h2.util.ObjectArray; 34 import org.h2.value.DataType; 35 import org.h2.value.Value; 36 import org.h2.value.ValueBoolean; 37 import org.h2.value.ValueByte; 38 import org.h2.value.ValueBytes; 39 import org.h2.value.ValueDate; 40 import org.h2.value.ValueDecimal; 41 import org.h2.value.ValueDouble; 42 import org.h2.value.ValueFloat; 43 import org.h2.value.ValueInt; 44 import org.h2.value.ValueLong; 45 import org.h2.value.ValueNull; 46 import org.h2.value.ValueShort; 47 import org.h2.value.ValueString; 48 import org.h2.value.ValueTime; 49 import org.h2.value.ValueTimestamp; 50 51 57 59 63 public class JdbcPreparedStatement extends JdbcStatement implements PreparedStatement { 64 65 private CommandInterface command; 66 private ObjectArray batchParameters; 67 68 75 public ResultSet executeQuery() throws SQLException { 76 try { 77 int id = getNextId(TraceObject.RESULT_SET); 78 if(debug()) { 79 debugCodeAssign("ResultSet", TraceObject.RESULT_SET, id); 80 debugCodeCall("executeQuery"); 81 } 82 checkClosed(); 83 closeOld(); 84 ResultInterface result; 85 synchronized(session) { 86 try { 87 setExecutingStatement(command); 88 boolean scrollable = resultSetType != ResultSet.TYPE_FORWARD_ONLY; 89 result = command.executeQuery(maxRows, scrollable); 90 } finally { 91 setExecutingStatement(null); 92 } 93 } 94 resultSet = new JdbcResultSet(session, conn, this, result, id, closedByResultSet); 95 return resultSet; 96 } catch(Throwable e) { 97 throw logAndConvert(e); 98 } 99 } 100 101 112 public int executeUpdate() throws SQLException { 113 try { 114 debugCodeCall("executeUpdate"); 115 checkClosed(); 116 return executeUpdateInternal(); 117 } catch(Throwable e) { 118 throw logAndConvert(e); 119 } 120 } 121 122 private int executeUpdateInternal() throws SQLException { 123 closeOld(); 124 synchronized(session) { 125 try { 126 setExecutingStatement(command); 127 updateCount = command.executeUpdate(); 128 } finally { 129 setExecutingStatement(null); 130 } 131 } 132 return updateCount; 133 } 134 135 142 public boolean execute() throws SQLException { 143 try { 144 int id = getNextId(TraceObject.RESULT_SET); 145 if(debug()) { 146 debugCodeCall("execute"); 147 } 148 checkClosed(); 149 closeOld(); 150 boolean returnsResultSet; 151 synchronized(session) { 152 try { 153 setExecutingStatement(command); 154 if (command.isQuery()) { 155 returnsResultSet = true; 156 boolean scrollable = resultSetType != ResultSet.TYPE_FORWARD_ONLY; 157 ResultInterface result = command.executeQuery(maxRows, scrollable); 158 resultSet = new JdbcResultSet(session, conn, this, result, id, closedByResultSet); 159 } else { 160 returnsResultSet = false; 161 updateCount = command.executeUpdate(); 162 } 163 } finally { 164 setExecutingStatement(null); 165 } 166 } 167 return returnsResultSet; 168 } catch(Throwable e) { 169 throw logAndConvert(e); 170 } 171 } 172 173 178 public void clearParameters() throws SQLException { 179 try { 180 debugCodeCall("clearParameters"); 181 checkClosed(); 182 ObjectArray parameters = command.getParameters(); 183 for (int i = 0; i < parameters.size(); i++) { 184 ParameterInterface param = (ParameterInterface) parameters.get(i); 185 param.setValue(null); 186 } 187 } catch(Throwable e) { 188 throw logAndConvert(e); 189 } 190 } 191 192 197 public ResultSet executeQuery(String sql) throws SQLException { 198 try { 199 debugCodeCall("executeQuery", sql); 200 throw Message.getUnsupportedException(); 201 } catch(Throwable e) { 202 throw logAndConvert(e); 203 } 204 } 205 206 211 public void addBatch(String sql) throws SQLException { 212 try { 213 debugCodeCall("addBatch", sql); 214 throw Message.getUnsupportedException(); 215 } catch(Throwable e) { 216 throw logAndConvert(e); 217 } 218 } 219 220 225 public int executeUpdate(String sql) throws SQLException { 226 try { 227 debugCodeCall("executeUpdate", sql); 228 throw Message.getUnsupportedException(); 229 } catch(Throwable e) { 230 throw logAndConvert(e); 231 } 232 } 233 234 239 public boolean execute(String sql) throws SQLException { 240 try { 241 debugCodeCall("execute", sql); 242 throw Message.getUnsupportedException(); 243 } catch(Throwable e) { 244 throw logAndConvert(e); 245 } 246 } 247 248 250 257 public void setNull(int parameterIndex, int sqlType) throws SQLException { 258 try { 259 if(debug()) { 260 debugCode("setNull("+parameterIndex+", "+sqlType+");"); 261 } 262 setParameter(parameterIndex, ValueNull.INSTANCE); 263 } catch(Throwable e) { 264 throw logAndConvert(e); 265 } 266 } 267 268 275 public void setInt(int parameterIndex, int x) throws SQLException { 276 try { 277 if(debug()) { 278 debugCode("setInt("+parameterIndex+", "+x+");"); 279 } 280 setParameter(parameterIndex, ValueInt.get(x)); 281 } catch(Throwable e) { 282 throw logAndConvert(e); 283 } 284 } 285 286 293 public void setString(int parameterIndex, String x) throws SQLException { 294 try { 295 if(debug()) { 296 debugCode("setString("+parameterIndex+", "+quote(x)+");"); 297 } 298 Value v = x == null ? (Value) ValueNull.INSTANCE : ValueString.get(x); 299 setParameter(parameterIndex, v); 300 } catch(Throwable e) { 301 throw logAndConvert(e); 302 } 303 } 304 305 312 public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException { 313 try { 314 if(debug()) { 315 debugCode("setBigDecimal("+parameterIndex+", " + quoteBigDecimal(x) + ");"); 316 } 317 Value v = x == null ? (Value) ValueNull.INSTANCE : ValueDecimal.get(x); 318 setParameter(parameterIndex, v); 319 } catch(Throwable e) { 320 throw logAndConvert(e); 321 } 322 } 323 324 331 public void setDate(int parameterIndex, java.sql.Date x) throws SQLException { 332 try { 333 if(debug()) { 334 debugCode("setDate("+parameterIndex+", " + quoteDate(x) + ");"); 335 } 336 Value v = x == null ? (Value) ValueNull.INSTANCE : ValueDate.get(x); 337 setParameter(parameterIndex, v); 338 } catch(Throwable e) { 339 throw logAndConvert(e); 340 } 341 } 342 343 350 public void setTime(int parameterIndex, java.sql.Time x) throws SQLException { 351 try { 352 if(debug()) { 353 debugCode("setTime("+parameterIndex+", " + quoteTime(x) + ");"); 354 } 355 Value v = x == null ? (Value) ValueNull.INSTANCE : ValueTime.get(x); 356 setParameter(parameterIndex, v); 357 } catch(Throwable e) { 358 throw logAndConvert(e); 359 } 360 } 361 362 369 public void setTimestamp(int parameterIndex, java.sql.Timestamp x) throws SQLException { 370 try { 371 if(debug()) { 372 debugCode("setTimestamp("+parameterIndex+", " + quoteTimestamp(x) + ");"); 373 } 374 Value v = x == null ? (Value) ValueNull.INSTANCE : ValueTimestamp.get(x); 375 setParameter(parameterIndex, v); 376 } catch(Throwable e) { 377 throw logAndConvert(e); 378 } 379 } 380 381 388 public void setObject(int parameterIndex, Object x) throws SQLException { 389 try { 390 if(debug()) { 391 debugCode("setObject("+parameterIndex+", x);"); 392 } 393 if (x == null) { 394 setParameter(parameterIndex, ValueNull.INSTANCE); 396 } else { 397 setParameter(parameterIndex, DataType.convertToValue(session, x, Value.UNKNOWN)); 398 } 399 } catch(Throwable e) { 400 throw logAndConvert(e); 401 } 402 } 403 404 413 public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException { 414 try { 415 if(debug()) { 416 debugCode("setObject("+parameterIndex+", x, "+targetSqlType+");"); 417 } 418 int type = DataType.convertSQLTypeToValueType(targetSqlType); 419 if (x == null) { 420 setParameter(parameterIndex, ValueNull.INSTANCE); 421 } else { 422 Value v = DataType.convertToValue(session, x, type); 423 setParameter(parameterIndex, v.convertTo(type)); 424 } 425 } catch(Throwable e) { 426 throw logAndConvert(e); 427 } 428 } 429 430 440 public void setObject(int parameterIndex, Object x, int targetSqlType, int scale) throws SQLException { 441 try { 442 if(debug()) { 443 debugCode("setObject("+parameterIndex+", x, "+targetSqlType+", "+scale+");"); 444 } 445 setObject(parameterIndex, x, targetSqlType); 446 } catch(Throwable e) { 447 throw logAndConvert(e); 448 } 449 } 450 451 458 public void setBoolean(int parameterIndex, boolean x) throws SQLException { 459 try { 460 if(debug()) { 461 debugCode("setBoolean("+parameterIndex+", "+x+");"); 462 } 463 setParameter(parameterIndex, ValueBoolean.get(x)); 464 } catch(Throwable e) { 465 throw logAndConvert(e); 466 } 467 } 468 469 476 public void setByte(int parameterIndex, byte x) throws SQLException { 477 try { 478 if(debug()) { 479 debugCode("setByte("+parameterIndex+", "+x+");"); 480 } 481 setParameter(parameterIndex, ValueByte.get(x)); 482 } catch(Throwable e) { 483 throw logAndConvert(e); 484 } 485 } 486 487 494 public void setShort(int parameterIndex, short x) throws SQLException { 495 try { 496 if(debug()) { 497 debugCode("setShort("+parameterIndex+", "+x+");"); 498 } 499 setParameter(parameterIndex, ValueShort.get(x)); 500 } catch(Throwable e) { 501 throw logAndConvert(e); 502 } 503 } 504 505 512 public void setLong(int parameterIndex, long x) throws SQLException { 513 try { 514 if(debug()) { 515 debugCode("setLong("+parameterIndex+", "+x+");"); 516 } 517 setParameter(parameterIndex, ValueLong.get(x)); 518 } catch(Throwable e) { 519 throw logAndConvert(e); 520 } 521 } 522 523 530 public void setFloat(int parameterIndex, float x) throws SQLException { 531 try { 532 if(debug()) { 533 debugCode("setFloat("+parameterIndex+", "+x+"f);"); 534 } 535 setParameter(parameterIndex, ValueFloat.get(x)); 536 } catch(Throwable e) { 537 throw logAndConvert(e); 538 } 539 } 540 541 548 public void setDouble(int parameterIndex, double x) throws SQLException { 549 try { 550 if(debug()) { 551 debugCode("setDouble("+parameterIndex+", "+x+");"); 552 } 553 setParameter(parameterIndex, ValueDouble.get(x)); 554 } catch(Throwable e) { 555 throw logAndConvert(e); 556 } 557 } 558 559 564 public void setRef(int parameterIndex, Ref x) throws SQLException { 565 try { 566 if(debug()) { 567 debugCode("setRef("+parameterIndex+", x);"); 568 } 569 throw Message.getUnsupportedException(); 570 } catch(Throwable e) { 571 throw logAndConvert(e); 572 } 573 } 574 575 583 public void setDate(int parameterIndex, java.sql.Date x, Calendar calendar) throws SQLException { 584 try { 585 if(debug()) { 586 debugCode("setDate("+parameterIndex+", " + quoteDate(x) + ", calendar);"); 587 } 588 if (x == null) { 589 setParameter(parameterIndex, ValueNull.INSTANCE); 590 } else { 591 setParameter(parameterIndex, DateTimeUtils.convertDateToUniversal(x, calendar)); 592 } 593 } catch(Throwable e) { 594 throw logAndConvert(e); 595 } 596 } 597 598 606 public void setTime(int parameterIndex, java.sql.Time x, Calendar calendar) throws SQLException { 607 try { 608 if(debug()) { 609 debugCode("setTime("+parameterIndex+", " + quoteTime(x) + ", calendar);"); 610 } 611 if (x == null) { 612 setParameter(parameterIndex, ValueNull.INSTANCE); 613 } else { 614 setParameter(parameterIndex, DateTimeUtils.convertTimeToUniversal(x, calendar)); 615 } 616 } catch(Throwable e) { 617 throw logAndConvert(e); 618 } 619 } 620 621 629 public void setTimestamp(int parameterIndex, java.sql.Timestamp x, Calendar calendar) throws SQLException { 630 try { 631 if(debug()) { 632 debugCode("setTimestamp("+parameterIndex+", " + quoteTimestamp(x) + ", calendar);"); 633 } 634 if (x == null) { 635 setParameter(parameterIndex, ValueNull.INSTANCE); 636 } else { 637 setParameter(parameterIndex, DateTimeUtils.convertTimestampToUniversal(x, calendar)); 638 } 639 } catch(Throwable e) { 640 throw logAndConvert(e); 641 } 642 } 643 644 651 public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException { 652 try { 653 if(debug()) { 654 debugCode("setUnicodeStream("+parameterIndex+", x, "+length+");"); 655 } 656 throw Message.getUnsupportedException(); 657 } catch(Throwable e) { 658 throw logAndConvert(e); 659 } 660 } 661 662 670 public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException { 671 try { 672 if(debug()) { 673 debugCode("setNull("+parameterIndex+", "+sqlType+", "+quote(typeName)+");"); 674 } 675 setNull(parameterIndex, sqlType); 676 } catch(Throwable e) { 677 throw logAndConvert(e); 678 } 679 } 680 681 688 public void setBlob(int parameterIndex, Blob x) throws SQLException { 689 try { 690 if(debug()) { 691 debugCode("setBlob("+parameterIndex+", x);"); 692 } 693 checkClosed(); 694 Value v; 695 if(x == null) { 696 v = ValueNull.INSTANCE; 697 } else { 698 v = conn.createBlob(x.getBinaryStream(), -1); 699 } 700 setParameter(parameterIndex, v); 701 } catch(Throwable e) { 702 throw logAndConvert(e); 703 } 704 } 705 706 713 public void setBlob(int parameterIndex, InputStream x) throws SQLException { 714 try { 715 if(debug()) { 716 debugCode("setBlob("+parameterIndex+", x);"); 717 } 718 checkClosed(); 719 Value v = conn.createBlob(x, -1); 720 setParameter(parameterIndex, v); 721 } catch(Throwable e) { 722 throw logAndConvert(e); 723 } 724 } 725 726 733 public void setClob(int parameterIndex, Clob x) throws SQLException { 734 try { 735 if(debug()) { 736 debugCode("setClob("+parameterIndex+", x);"); 737 } 738 checkClosed(); 739 Value v; 740 if(x == null) { 741 v = ValueNull.INSTANCE; 742 } else { 743 v = conn.createClob(x.getCharacterStream(), -1); 744 } 745 setParameter(parameterIndex, v); 746 } catch(Throwable e) { 747 throw logAndConvert(e); 748 } 749 } 750 751 758 public void setClob(int parameterIndex, Reader x) throws SQLException { 759 try { 760 if(debug()) { 761 debugCode("setClob("+parameterIndex+", x);"); 762 } 763 checkClosed(); 764 Value v; 765 if(x == null) { 766 v = ValueNull.INSTANCE; 767 } else { 768 v = conn.createClob(x, -1); 769 } 770 setParameter(parameterIndex, v); 771 } catch(Throwable e) { 772 throw logAndConvert(e); 773 } 774 } 775 776 781 public void setArray(int parameterIndex, Array x) throws SQLException { 782 try { 783 if(debug()) { 784 debugCode("setArray("+parameterIndex+", x);"); 785 } 786 throw Message.getUnsupportedException(); 787 } catch(Throwable e) { 788 throw logAndConvert(e); 789 } 790 } 791 792 799 public void setBytes(int parameterIndex, byte[] x) throws SQLException { 800 try { 801 if(debug()) { 802 debugCode("setBytes("+parameterIndex+", "+quoteBytes(x)+");"); 803 } 804 Value v = x == null ? (Value) ValueNull.INSTANCE : ValueBytes.get(x); 806 setParameter(parameterIndex, v); 807 } catch(Throwable e) { 808 throw logAndConvert(e); 809 } 810 } 811 812 820 public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException { 821 try { 822 if(debug()) { 823 debugCode("setBinaryStream("+parameterIndex+", x, "+length+");"); 824 } 825 checkClosed(); 826 Value v = conn.createBlob(x, length); 827 setParameter(parameterIndex, v); 828 } catch(Throwable e) { 829 throw logAndConvert(e); 830 } 831 } 832 833 841 public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException { 842 setBinaryStream(parameterIndex, x, (long) length); 843 } 844 845 853 public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException { 854 setBinaryStream(parameterIndex, x, -1); 855 } 856 857 865 public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException { 866 setAsciiStream(parameterIndex, x, (long) length); 867 } 868 869 877 public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException { 878 try { 879 if(debug()) { 880 debugCode("setAsciiStream("+parameterIndex+", x, "+length+");"); 881 } 882 checkClosed(); 883 Value v = conn.createClob(IOUtils.getAsciiReader(x), length); 884 setParameter(parameterIndex, v); 885 } catch(Throwable e) { 886 throw logAndConvert(e); 887 } 888 } 889 890 897 public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException { 898 setAsciiStream(parameterIndex, x, -1); 899 } 900 901 909 public void setCharacterStream(int parameterIndex, Reader x, int length) throws SQLException { 910 setCharacterStream(parameterIndex, x, (long) length); 911 } 912 913 920 public void setCharacterStream(int parameterIndex, Reader x) throws SQLException { 921 setCharacterStream(parameterIndex, x, -1); 922 } 923 924 932 public void setCharacterStream(int parameterIndex, Reader x, long length) throws SQLException { 933 try { 934 if(debug()) { 935 debugCode("setCharacterStream("+parameterIndex+", x, "+length+");"); 936 } 937 checkClosed(); 938 Value v = conn.createClob(x, length); 939 setParameter(parameterIndex, v); 940 } catch(Throwable e) { 941 throw logAndConvert(e); 942 } 943 } 944 945 950 public void setURL(int parameterIndex, URL x) throws SQLException { 951 try { 952 if(debug()) { 953 debugCode("setURL("+parameterIndex+", x);"); 954 } 955 throw Message.getUnsupportedException(); 956 } catch(Throwable e) { 957 throw logAndConvert(e); 958 } 959 } 960 961 967 public ResultSetMetaData getMetaData() throws SQLException { 968 try { 969 debugCodeCall("getMetaData"); 970 checkClosed(); 971 return null; 972 } catch(Throwable e) { 973 throw logAndConvert(e); 974 } 975 } 976 977 978 981 public void clearBatch() throws SQLException { 982 try { 983 debugCodeCall("clearBatch"); 984 checkClosed(); 985 batchParameters = null; 986 } catch(Throwable e) { 987 throw logAndConvert(e); 988 } 989 } 990 991 996 public void close() throws SQLException { 997 try { 998 super.close(); 999 if(command != null) { 1000 command.close(); 1001 command = null; 1002 } 1003 } catch(Throwable e) { 1004 throw logAndConvert(e); 1005 } 1006 } 1007 1008 1013 public int[] executeBatch() throws SQLException { 1014 try { 1015 debugCodeCall("executeBatch"); 1016 checkClosed(); 1017 if (batchParameters == null) { 1018 batchParameters = new ObjectArray(); 1020 } 1021 int[] result = new int[batchParameters.size()]; 1022 boolean error = false; 1023 SQLException next = null; 1024 for (int i = 0; i < batchParameters.size(); i++) { 1025 ObjectArray parameters = command.getParameters(); 1026 Value[] set = (Value[]) batchParameters.get(i); 1027 for (int j = 0; j < set.length; j++) { 1028 Value value = set[j]; 1029 ParameterInterface param = (ParameterInterface) parameters.get(j); 1030 param.setValue(value); 1031 } 1032 try { 1033 result[i] = executeUpdateInternal(); 1034 } catch (SQLException e) { 1035 if(next == null) { 1036 next = e; 1037 } else { 1038 e.setNextException(next); 1039 next = e; 1040 } 1041 logAndConvert(e); 1042 result[i] = Statement.EXECUTE_FAILED; 1044 error = true; 1046 } 1047 } 1048 batchParameters = null; 1049 if (error) { 1050 JdbcBatchUpdateException bue = new JdbcBatchUpdateException(next, result); 1051 bue.setNextException(next); 1052 throw bue; 1053 } 1054 return result; 1055 } catch(Throwable e) { 1056 throw logAndConvert(e); 1057 } 1058 } 1059 1060 1063 public void addBatch() throws SQLException { 1064 try { 1065 debugCodeCall("addBatch"); 1066 checkClosed(); 1067 ObjectArray parameters = command.getParameters(); 1068 Value[] set = new Value[parameters.size()]; 1069 for (int i = 0; i < parameters.size(); i++) { 1070 ParameterInterface param = (ParameterInterface) parameters.get(i); 1071 Value value = param.getParamValue(); 1072 set[i] = value; 1073 } 1074 if (batchParameters == null) { 1075 batchParameters = new ObjectArray(); 1076 } 1077 batchParameters.add(set); 1078 } catch(Throwable e) { 1079 throw logAndConvert(e); 1080 } 1081 } 1082 1083 1088 public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException { 1089 try { 1090 if(debug()) { 1091 debugCode("executeUpdate("+quote(sql)+", "+autoGeneratedKeys+");"); 1092 } 1093 throw Message.getUnsupportedException(); 1094 } catch(Throwable e) { 1095 throw logAndConvert(e); 1096 } 1097 } 1098 1099 1100 1105 public int executeUpdate(String sql, int[] columnIndexes) throws SQLException { 1106 try { 1107 if (debug()) { 1108 debugCode("executeUpdate(" + quote(sql) + ", " + quoteIntArray(columnIndexes) + ");"); 1109 } 1110 throw Message.getUnsupportedException(); 1111 } catch (Exception e) { 1112 throw logAndConvert(e); 1113 } 1114 } 1115 1116 1121 public int executeUpdate(String sql, String [] columnNames) throws SQLException { 1122 try { 1123 if (debug()) { 1124 debugCode("executeUpdate(" + quote(sql) + ", " + quoteArray(columnNames) + ");"); 1125 } 1126 throw Message.getUnsupportedException(); 1127 } catch (Exception e) { 1128 throw logAndConvert(e); 1129 } 1130 } 1131 1132 1137 public boolean execute(String sql, int autoGeneratedKeys) throws SQLException { 1138 try { 1139 if (debug()) { 1140 debugCode("execute(" + quote(sql) + ", " + autoGeneratedKeys + ");"); 1141 } 1142 throw Message.getUnsupportedException(); 1143 } catch (Exception e) { 1144 throw logAndConvert(e); 1145 } 1146 } 1147 1148 1153 public boolean execute(String sql, int[] columnIndexes) throws SQLException { 1154 try { 1155 if (debug()) { 1156 debugCode("execute(" + quote(sql) + ", " + quoteIntArray(columnIndexes) + ");"); 1157 } 1158 throw Message.getUnsupportedException(); 1159 } catch (Exception e) { 1160 throw logAndConvert(e); 1161 } 1162 } 1163 1164 1169 public boolean execute(String sql, String [] columnNames) throws SQLException { 1170 try { 1171 if (debug()) { 1172 debugCode("execute(" + quote(sql) + ", " + quoteArray(columnNames) + ");"); 1173 } 1174 throw Message.getUnsupportedException(); 1175 } catch (Exception e) { 1176 throw logAndConvert(e); 1177 } 1178 } 1179 1180 1185 public ParameterMetaData getParameterMetaData() throws SQLException { 1187 try { 1188 int id = getNextId(TraceObject.PARAMETER_META_DATA); 1189 if(debug()) { 1190 debugCodeAssign("ParameterMetaData", TraceObject.PARAMETER_META_DATA, id); 1191 debugCodeCall("getParameterMetaData"); 1192 } 1193 checkClosed(); 1194 JdbcParameterMetaData meta = new JdbcParameterMetaData(session, this, command, id); 1195 return meta; 1196 } catch(Throwable e) { 1197 throw logAndConvert(e); 1198 } 1199 } 1200 1202 1204 JdbcPreparedStatement(SessionInterface session, JdbcConnection conn, String sql, int resultSetType, int id, boolean closeWithResultSet) throws SQLException { 1205 super(session, conn, resultSetType, id, closeWithResultSet); 1206 setTrace(session.getTrace(), TraceObject.PREPARED_STATEMENT, id); 1207 command = conn.prepareCommand(sql); 1208 } 1209 1210 private void setParameter(int parameterIndex, Value value) throws SQLException { 1211 checkClosed(); 1212 parameterIndex--; 1213 ObjectArray parameters = command.getParameters(); 1214 if (parameterIndex < 0 || parameterIndex >= parameters.size()) { 1215 throw Message.getInvalidValueException("" + (parameterIndex + 1), "parameterIndex"); 1216 } 1217 ParameterInterface param = (ParameterInterface) parameters.get(parameterIndex); 1218 param.setValue(value); 1219 } 1220 1221 1225 1231 1233 1240 public void setNString(int parameterIndex, String x) throws SQLException { 1241 try { 1242 if(debug()) { 1243 debugCode("setNString("+parameterIndex+", "+quote(x)+");"); 1244 } 1245 Value v = x == null ? (Value) ValueNull.INSTANCE : ValueString.get(x); 1246 setParameter(parameterIndex, v); 1247 } catch(Throwable e) { 1248 throw logAndConvert(e); 1249 } 1250 } 1251 1252 1260 public void setNCharacterStream(int parameterIndex, Reader x, long length) throws SQLException { 1261 try { 1262 if(debug()) { 1263 debugCode("setNCharacterStream("+parameterIndex+", x, "+length+");"); 1264 } 1265 checkClosed(); 1266 Value v = conn.createClob(x, length); 1267 setParameter(parameterIndex, v); 1268 } catch(Throwable e) { 1269 throw logAndConvert(e); 1270 } 1271 } 1272 1273 1280 public void setNCharacterStream(int parameterIndex, Reader x) throws SQLException { 1281 setNCharacterStream(parameterIndex, x, -1); 1282 } 1283 1284 1291 1311 1313 1320 public void setNClob(int parameterIndex, Reader x) throws SQLException { 1321 try { 1322 if(debug()) { 1323 debugCode("setNClob("+parameterIndex+", x);"); 1324 } 1325 checkClosed(); 1326 Value v = conn.createClob(x, -1); 1327 setParameter(parameterIndex, v); 1328 } catch(Throwable e) { 1329 throw logAndConvert(e); 1330 } 1331 } 1332 1333 1340 public void setClob(int parameterIndex, Reader x, long length) throws SQLException { 1341 try { 1342 if(debug()) { 1343 debugCode("setClob("+parameterIndex+", x, "+length+");"); 1344 } 1345 checkClosed(); 1346 Value v = conn.createClob(x, length); 1347 setParameter(parameterIndex, v); 1348 } catch(Throwable e) { 1349 throw logAndConvert(e); 1350 } 1351 } 1352 1353 1360 public void setBlob(int parameterIndex, InputStream x, long length) throws SQLException { 1361 try { 1362 if(debug()) { 1363 debugCode("setBlob("+parameterIndex+", x, "+length+");"); 1364 } 1365 checkClosed(); 1366 Value v = conn.createBlob(x, length); 1367 setParameter(parameterIndex, v); 1368 } catch(Throwable e) { 1369 throw logAndConvert(e); 1370 } 1371 } 1372 1373 1380 public void setNClob(int parameterIndex, Reader x, long length) throws SQLException { 1381 try { 1382 if(debug()) { 1383 debugCode("setNClob("+parameterIndex+", x, "+length+");"); 1384 } 1385 checkClosed(); 1386 Value v = conn.createClob(x, length); 1387 setParameter(parameterIndex, v); 1388 } catch(Throwable e) { 1389 throw logAndConvert(e); 1390 } 1391 } 1392 1393 1397 1403 1405} 1406 | Popular Tags |