1 19 package com.mysql.jdbc.jdbc2.optional; 20 21 import com.mysql.jdbc.SQLError; 22 23 import java.io.InputStream ; 24 import java.io.Reader ; 25 26 import java.math.BigDecimal ; 27 28 import java.net.URL ; 29 30 import java.sql.Array ; 31 import java.sql.Blob ; 32 import java.sql.Clob ; 33 import java.sql.Date ; 34 import java.sql.ParameterMetaData ; 35 import java.sql.PreparedStatement ; 36 import java.sql.Ref ; 37 import java.sql.ResultSet ; 38 import java.sql.ResultSetMetaData ; 39 import java.sql.SQLException ; 40 import java.sql.Time ; 41 import java.sql.Timestamp ; 42 43 import java.util.Calendar ; 44 45 46 54 class PreparedStatementWrapper extends StatementWrapper 55 implements PreparedStatement { 56 PreparedStatementWrapper(MysqlPooledConnection conn, 57 PreparedStatement toWrap) { 58 super(conn, toWrap); 59 } 60 61 64 public void setArray(int parameterIndex, Array x) throws SQLException { 65 try { 66 if (this.wrappedStmt != null) { 67 ((PreparedStatement ) this.wrappedStmt).setArray(parameterIndex, 68 x); 69 } else { 70 throw new SQLException ("No operations allowed after statement closed", 71 SQLError.SQL_STATE_GENERAL_ERROR); 72 } 73 } catch (SQLException sqlEx) { 74 checkAndFireConnectionError(sqlEx); 75 } 76 } 77 78 81 public void setAsciiStream(int parameterIndex, InputStream x, int length) 82 throws SQLException { 83 try { 84 if (this.wrappedStmt != null) { 85 ((PreparedStatement ) this.wrappedStmt).setAsciiStream(parameterIndex, 86 x, length); 87 } else { 88 throw new SQLException ("No operations allowed after statement closed", 89 SQLError.SQL_STATE_GENERAL_ERROR); 90 } 91 } catch (SQLException sqlEx) { 92 checkAndFireConnectionError(sqlEx); 93 } 94 } 95 96 99 public void setBigDecimal(int parameterIndex, BigDecimal x) 100 throws SQLException { 101 try { 102 if (this.wrappedStmt != null) { 103 ((PreparedStatement ) this.wrappedStmt).setBigDecimal(parameterIndex, 104 x); 105 } else { 106 throw new SQLException ("No operations allowed after statement closed", 107 SQLError.SQL_STATE_GENERAL_ERROR); 108 } 109 } catch (SQLException sqlEx) { 110 checkAndFireConnectionError(sqlEx); 111 } 112 } 113 114 117 public void setBinaryStream(int parameterIndex, InputStream x, int length) 118 throws SQLException { 119 try { 120 if (this.wrappedStmt != null) { 121 ((PreparedStatement ) this.wrappedStmt).setBinaryStream(parameterIndex, 122 x, length); 123 } else { 124 throw new SQLException ("No operations allowed after statement closed", 125 SQLError.SQL_STATE_GENERAL_ERROR); 126 } 127 } catch (SQLException sqlEx) { 128 checkAndFireConnectionError(sqlEx); 129 } 130 } 131 132 135 public void setBlob(int parameterIndex, Blob x) throws SQLException { 136 try { 137 if (this.wrappedStmt != null) { 138 ((PreparedStatement ) this.wrappedStmt).setBlob(parameterIndex, x); 139 } else { 140 throw new SQLException ("No operations allowed after statement closed", 141 SQLError.SQL_STATE_GENERAL_ERROR); 142 } 143 } catch (SQLException sqlEx) { 144 checkAndFireConnectionError(sqlEx); 145 } 146 } 147 148 151 public void setBoolean(int parameterIndex, boolean x) 152 throws SQLException { 153 try { 154 if (this.wrappedStmt != null) { 155 ((PreparedStatement ) this.wrappedStmt).setBoolean(parameterIndex, 156 x); 157 } else { 158 throw new SQLException ("No operations allowed after statement closed", 159 SQLError.SQL_STATE_GENERAL_ERROR); 160 } 161 } catch (SQLException sqlEx) { 162 checkAndFireConnectionError(sqlEx); 163 } 164 } 165 166 169 public void setByte(int parameterIndex, byte x) throws SQLException { 170 try { 171 if (this.wrappedStmt != null) { 172 ((PreparedStatement ) this.wrappedStmt).setByte(parameterIndex, x); 173 } else { 174 throw new SQLException ("No operations allowed after statement closed", 175 SQLError.SQL_STATE_GENERAL_ERROR); 176 } 177 } catch (SQLException sqlEx) { 178 checkAndFireConnectionError(sqlEx); 179 } 180 } 181 182 185 public void setBytes(int parameterIndex, byte[] x) 186 throws SQLException { 187 try { 188 if (this.wrappedStmt != null) { 189 ((PreparedStatement ) this.wrappedStmt).setBytes(parameterIndex, 190 x); 191 } else { 192 throw new SQLException ("No operations allowed after statement closed", 193 SQLError.SQL_STATE_GENERAL_ERROR); 194 } 195 } catch (SQLException sqlEx) { 196 checkAndFireConnectionError(sqlEx); 197 } 198 } 199 200 203 public void setCharacterStream(int parameterIndex, Reader reader, int length) 204 throws SQLException { 205 try { 206 if (this.wrappedStmt != null) { 207 ((PreparedStatement ) this.wrappedStmt).setCharacterStream(parameterIndex, 208 reader, length); 209 } else { 210 throw new SQLException ("No operations allowed after statement closed", 211 SQLError.SQL_STATE_GENERAL_ERROR); 212 } 213 } catch (SQLException sqlEx) { 214 checkAndFireConnectionError(sqlEx); 215 } 216 } 217 218 221 public void setClob(int parameterIndex, Clob x) throws SQLException { 222 try { 223 if (this.wrappedStmt != null) { 224 ((PreparedStatement ) this.wrappedStmt).setClob(parameterIndex, x); 225 } else { 226 throw new SQLException ("No operations allowed after statement closed", 227 SQLError.SQL_STATE_GENERAL_ERROR); 228 } 229 } catch (SQLException sqlEx) { 230 checkAndFireConnectionError(sqlEx); 231 } 232 } 233 234 237 public void setDate(int parameterIndex, Date x) throws SQLException { 238 try { 239 if (this.wrappedStmt != null) { 240 ((PreparedStatement ) this.wrappedStmt).setDate(parameterIndex, x); 241 } else { 242 throw new SQLException ("No operations allowed after statement closed", 243 SQLError.SQL_STATE_GENERAL_ERROR); 244 } 245 } catch (SQLException sqlEx) { 246 checkAndFireConnectionError(sqlEx); 247 } 248 } 249 250 253 public void setDate(int parameterIndex, Date x, Calendar cal) 254 throws SQLException { 255 try { 256 if (this.wrappedStmt != null) { 257 ((PreparedStatement ) this.wrappedStmt).setDate(parameterIndex, 258 x, cal); 259 } else { 260 throw new SQLException ("No operations allowed after statement closed", 261 SQLError.SQL_STATE_GENERAL_ERROR); 262 } 263 } catch (SQLException sqlEx) { 264 checkAndFireConnectionError(sqlEx); 265 } 266 } 267 268 271 public void setDouble(int parameterIndex, double x) 272 throws SQLException { 273 try { 274 if (this.wrappedStmt != null) { 275 ((PreparedStatement ) this.wrappedStmt).setDouble(parameterIndex, 276 x); 277 } else { 278 throw new SQLException ("No operations allowed after statement closed", 279 SQLError.SQL_STATE_GENERAL_ERROR); 280 } 281 } catch (SQLException sqlEx) { 282 checkAndFireConnectionError(sqlEx); 283 } 284 } 285 286 289 public void setFloat(int parameterIndex, float x) throws SQLException { 290 try { 291 if (this.wrappedStmt != null) { 292 ((PreparedStatement ) this.wrappedStmt).setFloat(parameterIndex, 293 x); 294 } else { 295 throw new SQLException ("No operations allowed after statement closed", 296 SQLError.SQL_STATE_GENERAL_ERROR); 297 } 298 } catch (SQLException sqlEx) { 299 checkAndFireConnectionError(sqlEx); 300 } 301 } 302 303 306 public void setInt(int parameterIndex, int x) throws SQLException { 307 try { 308 if (this.wrappedStmt != null) { 309 ((PreparedStatement ) this.wrappedStmt).setInt(parameterIndex, x); 310 } else { 311 throw new SQLException ("No operations allowed after statement closed", 312 SQLError.SQL_STATE_GENERAL_ERROR); 313 } 314 } catch (SQLException sqlEx) { 315 checkAndFireConnectionError(sqlEx); 316 } 317 } 318 319 322 public void setLong(int parameterIndex, long x) throws SQLException { 323 try { 324 if (this.wrappedStmt != null) { 325 ((PreparedStatement ) this.wrappedStmt).setLong(parameterIndex, x); 326 } else { 327 throw new SQLException ("No operations allowed after statement closed", 328 SQLError.SQL_STATE_GENERAL_ERROR); 329 } 330 } catch (SQLException sqlEx) { 331 checkAndFireConnectionError(sqlEx); 332 } 333 } 334 335 338 public ResultSetMetaData getMetaData() throws SQLException { 339 try { 340 if (this.wrappedStmt != null) { 341 return ((PreparedStatement ) this.wrappedStmt).getMetaData(); 342 } else { 343 throw new SQLException ("No operations allowed after statement closed", 344 SQLError.SQL_STATE_GENERAL_ERROR); 345 } 346 } catch (SQLException sqlEx) { 347 checkAndFireConnectionError(sqlEx); 348 } 349 350 return null; 351 } 352 353 356 public void setNull(int parameterIndex, int sqlType) 357 throws SQLException { 358 try { 359 if (this.wrappedStmt != null) { 360 ((PreparedStatement ) this.wrappedStmt).setNull(parameterIndex, 361 sqlType); 362 } else { 363 throw new SQLException ("No operations allowed after statement closed", 364 SQLError.SQL_STATE_GENERAL_ERROR); 365 } 366 } catch (SQLException sqlEx) { 367 checkAndFireConnectionError(sqlEx); 368 } 369 } 370 371 374 public void setNull(int parameterIndex, int sqlType, String typeName) 375 throws SQLException { 376 try { 377 if (this.wrappedStmt != null) { 378 ((PreparedStatement ) this.wrappedStmt).setNull(parameterIndex, 379 sqlType, typeName); 380 } else { 381 throw new SQLException ("No operations allowed after statement closed", 382 SQLError.SQL_STATE_GENERAL_ERROR); 383 } 384 } catch (SQLException sqlEx) { 385 checkAndFireConnectionError(sqlEx); 386 } 387 } 388 389 392 public void setObject(int parameterIndex, Object x) 393 throws SQLException { 394 try { 395 if (this.wrappedStmt != null) { 396 ((PreparedStatement ) this.wrappedStmt).setObject(parameterIndex, 397 x); 398 } else { 399 throw new SQLException ("No operations allowed after statement closed", 400 SQLError.SQL_STATE_GENERAL_ERROR); 401 } 402 } catch (SQLException sqlEx) { 403 checkAndFireConnectionError(sqlEx); 404 } 405 } 406 407 410 public void setObject(int parameterIndex, Object x, int targetSqlType) 411 throws SQLException { 412 try { 413 if (this.wrappedStmt != null) { 414 ((PreparedStatement ) this.wrappedStmt).setObject(parameterIndex, 415 x, targetSqlType); 416 } else { 417 throw new SQLException ("No operations allowed after statement closed", 418 SQLError.SQL_STATE_GENERAL_ERROR); 419 } 420 } catch (SQLException sqlEx) { 421 checkAndFireConnectionError(sqlEx); 422 } 423 } 424 425 428 public void setObject(int parameterIndex, Object x, int targetSqlType, 429 int scale) throws SQLException { 430 try { 431 if (this.wrappedStmt != null) { 432 ((PreparedStatement ) this.wrappedStmt).setObject(parameterIndex, 433 x, scale); 434 } else { 435 throw new SQLException ("No operations allowed after statement closed", 436 SQLError.SQL_STATE_GENERAL_ERROR); 437 } 438 } catch (SQLException sqlEx) { 439 checkAndFireConnectionError(sqlEx); 440 } 441 } 442 443 446 public ParameterMetaData getParameterMetaData() throws SQLException { 447 try { 448 if (this.wrappedStmt != null) { 449 return ((PreparedStatement ) this.wrappedStmt) 450 .getParameterMetaData(); 451 } else { 452 throw new SQLException ("No operations allowed after statement closed", 453 SQLError.SQL_STATE_GENERAL_ERROR); 454 } 455 } catch (SQLException sqlEx) { 456 checkAndFireConnectionError(sqlEx); 457 } 458 459 return null; 460 } 461 462 465 public void setRef(int parameterIndex, Ref x) throws SQLException { 466 try { 467 if (this.wrappedStmt != null) { 468 ((PreparedStatement ) this.wrappedStmt).setRef(parameterIndex, x); 469 } else { 470 throw new SQLException ("No operations allowed after statement closed", 471 SQLError.SQL_STATE_GENERAL_ERROR); 472 } 473 } catch (SQLException sqlEx) { 474 checkAndFireConnectionError(sqlEx); 475 } 476 } 477 478 481 public void setShort(int parameterIndex, short x) throws SQLException { 482 try { 483 if (this.wrappedStmt != null) { 484 ((PreparedStatement ) this.wrappedStmt).setShort(parameterIndex, 485 x); 486 } else { 487 throw new SQLException ("No operations allowed after statement closed", 488 SQLError.SQL_STATE_GENERAL_ERROR); 489 } 490 } catch (SQLException sqlEx) { 491 checkAndFireConnectionError(sqlEx); 492 } 493 } 494 495 498 public void setString(int parameterIndex, String x) 499 throws SQLException { 500 try { 501 if (this.wrappedStmt != null) { 502 ((PreparedStatement ) this.wrappedStmt).setString(parameterIndex, 503 x); 504 } else { 505 throw new SQLException ("No operations allowed after statement closed", 506 SQLError.SQL_STATE_GENERAL_ERROR); 507 } 508 } catch (SQLException sqlEx) { 509 checkAndFireConnectionError(sqlEx); 510 } 511 } 512 513 516 public void setTime(int parameterIndex, Time x) throws SQLException { 517 try { 518 if (this.wrappedStmt != null) { 519 ((PreparedStatement ) this.wrappedStmt).setTime(parameterIndex, x); 520 } else { 521 throw new SQLException ("No operations allowed after statement closed", 522 SQLError.SQL_STATE_GENERAL_ERROR); 523 } 524 } catch (SQLException sqlEx) { 525 checkAndFireConnectionError(sqlEx); 526 } 527 } 528 529 532 public void setTime(int parameterIndex, Time x, Calendar cal) 533 throws SQLException { 534 try { 535 if (this.wrappedStmt != null) { 536 ((PreparedStatement ) this.wrappedStmt).setTime(parameterIndex, 537 x, cal); 538 } else { 539 throw new SQLException ("No operations allowed after statement closed", 540 SQLError.SQL_STATE_GENERAL_ERROR); 541 } 542 } catch (SQLException sqlEx) { 543 checkAndFireConnectionError(sqlEx); 544 } 545 } 546 547 550 public void setTimestamp(int parameterIndex, Timestamp x) 551 throws SQLException { 552 try { 553 if (this.wrappedStmt != null) { 554 ((PreparedStatement ) this.wrappedStmt).setTimestamp(parameterIndex, 555 x); 556 } else { 557 throw new SQLException ("No operations allowed after statement closed", 558 SQLError.SQL_STATE_GENERAL_ERROR); 559 } 560 } catch (SQLException sqlEx) { 561 checkAndFireConnectionError(sqlEx); 562 } 563 } 564 565 568 public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) 569 throws SQLException { 570 try { 571 if (this.wrappedStmt != null) { 572 ((PreparedStatement ) this.wrappedStmt).setTimestamp(parameterIndex, 573 x, cal); 574 } else { 575 throw new SQLException ("No operations allowed after statement closed", 576 SQLError.SQL_STATE_GENERAL_ERROR); 577 } 578 } catch (SQLException sqlEx) { 579 checkAndFireConnectionError(sqlEx); 580 } 581 } 582 583 586 public void setURL(int parameterIndex, URL x) throws SQLException { 587 try { 588 if (this.wrappedStmt != null) { 589 ((PreparedStatement ) this.wrappedStmt).setURL(parameterIndex, x); 590 } else { 591 throw new SQLException ("No operations allowed after statement closed", 592 SQLError.SQL_STATE_GENERAL_ERROR); 593 } 594 } catch (SQLException sqlEx) { 595 checkAndFireConnectionError(sqlEx); 596 } 597 } 598 599 612 public void setUnicodeStream(int parameterIndex, InputStream x, int length) 613 throws SQLException { 614 try { 615 if (this.wrappedStmt != null) { 616 ((PreparedStatement ) this.wrappedStmt).setUnicodeStream(parameterIndex, 617 x, length); 618 } else { 619 throw new SQLException ("No operations allowed after statement closed", 620 SQLError.SQL_STATE_GENERAL_ERROR); 621 } 622 } catch (SQLException sqlEx) { 623 checkAndFireConnectionError(sqlEx); 624 } 625 } 626 627 630 public void addBatch() throws SQLException { 631 try { 632 if (this.wrappedStmt != null) { 633 ((PreparedStatement ) this.wrappedStmt).addBatch(); 634 } else { 635 throw new SQLException ("No operations allowed after statement closed", 636 SQLError.SQL_STATE_GENERAL_ERROR); 637 } 638 } catch (SQLException sqlEx) { 639 checkAndFireConnectionError(sqlEx); 640 } 641 } 642 643 646 public void clearParameters() throws SQLException { 647 try { 648 if (this.wrappedStmt != null) { 649 ((PreparedStatement ) this.wrappedStmt).clearParameters(); 650 } else { 651 throw new SQLException ("No operations allowed after statement closed", 652 SQLError.SQL_STATE_GENERAL_ERROR); 653 } 654 } catch (SQLException sqlEx) { 655 checkAndFireConnectionError(sqlEx); 656 } 657 } 658 659 662 public boolean execute() throws SQLException { 663 try { 664 if (this.wrappedStmt != null) { 665 return ((PreparedStatement ) this.wrappedStmt).execute(); 666 } else { 667 throw new SQLException ("No operations allowed after statement closed", 668 SQLError.SQL_STATE_GENERAL_ERROR); 669 } 670 } catch (SQLException sqlEx) { 671 checkAndFireConnectionError(sqlEx); 672 } 673 674 return false; 676 } 678 679 682 public ResultSet executeQuery() throws SQLException { 683 try { 684 if (this.wrappedStmt != null) { 685 return ((PreparedStatement ) this.wrappedStmt).executeQuery(); 686 } else { 687 throw new SQLException ("No operations allowed after statement closed", 688 SQLError.SQL_STATE_GENERAL_ERROR); 689 } 690 } catch (SQLException sqlEx) { 691 checkAndFireConnectionError(sqlEx); 692 } 693 694 return null; 696 } 698 699 702 public int executeUpdate() throws SQLException { 703 try { 704 if (this.wrappedStmt != null) { 705 return ((PreparedStatement ) this.wrappedStmt).executeUpdate(); 706 } else { 707 throw new SQLException ("No operations allowed after statement closed", 708 SQLError.SQL_STATE_GENERAL_ERROR); 709 } 710 } catch (SQLException sqlEx) { 711 checkAndFireConnectionError(sqlEx); 712 } 713 714 return -1; 716 } 718 } 719 | Popular Tags |