1 21 22 package org.apache.derbyTesting.functionTests.util; 23 24 import org.apache.derbyTesting.functionTests.util.Formatters; 25 26 import java.sql.*; 27 import java.math.BigDecimal ; 28 31 public abstract class ProcedureTest extends SimpleProcedureTest implements ResultSet { 32 33 public static void zeroArg() { 34 System.out.println("zeroArg() called"); 35 } 36 37 public static void insertRow(int p1) throws SQLException { 38 insertRow(p1, "int"); 39 } 40 41 public static void insertRow(int p1, String p2) throws SQLException { 42 Connection conn = DriverManager.getConnection("jdbc:default:connection"); 43 PreparedStatement ps = conn.prepareStatement("insert into t1 values (?, ?)"); 44 ps.setInt(1, p1); 45 ps.setString(2, p2); 46 ps.executeUpdate(); 47 ps.close(); 48 conn.close(); 49 } 50 51 public static void updateRow(int p1) throws SQLException { 52 Connection conn = DriverManager.getConnection("jdbc:default:connection"); 53 PreparedStatement ps = conn.prepareStatement("update t1 set i=i+?"); 54 ps.setInt(1, p1); 55 ps.executeUpdate(); 56 ps.close(); 57 conn.close(); 58 } 59 60 public static void deleteRow(int p1) throws SQLException { 61 Connection conn = DriverManager.getConnection("jdbc:default:connection"); 62 PreparedStatement ps = conn.prepareStatement("delete from t1 where i=?"); 63 ps.setInt(1, p1); 64 ps.executeUpdate(); 65 ps.close(); 66 conn.close(); 67 } 68 69 public static void alterTable() throws SQLException { 70 Connection conn = DriverManager.getConnection("jdbc:default:connection"); 71 PreparedStatement ps = conn.prepareStatement("alter table t1 add column test integer"); 72 ps.execute(); 73 ps.close(); 74 conn.close(); 75 } 76 77 public static void dropTable() throws SQLException { 78 Connection conn = DriverManager.getConnection("jdbc:default:connection"); 79 PreparedStatement ps = conn.prepareStatement("drop table t1"); 80 ps.execute(); 81 ps.close(); 82 conn.close(); 83 } 84 85 public static void createIndex() throws SQLException { 86 Connection conn = DriverManager.getConnection("jdbc:default:connection"); 87 PreparedStatement ps = conn.prepareStatement("create index ix on t1(i,b)"); 88 ps.execute(); 89 ps.close(); 90 conn.close(); 91 } 92 93 public static void dropIndex() throws SQLException { 94 Connection conn = DriverManager.getConnection("jdbc:default:connection"); 95 PreparedStatement ps = conn.prepareStatement("drop index ix"); 96 ps.execute(); 97 ps.close(); 98 conn.close(); 99 } 100 101 public static void createTrigger() throws SQLException { 102 Connection conn = DriverManager.getConnection("jdbc:default:connection"); 103 PreparedStatement ps = conn.prepareStatement("create trigger test_trig" + 104 " AFTER delete on t1 for each STATEMENT mode db2sql insert into" + 105 " t1 values(20, 'twenty')"); 106 ps.execute(); 107 ps.close(); 108 conn.close(); 109 } 110 111 public static void dropTrigger() throws SQLException { 112 Connection conn = DriverManager.getConnection("jdbc:default:connection"); 113 PreparedStatement ps = conn.prepareStatement("drop trigger test_trig"); 114 ps.execute(); 115 ps.close(); 116 conn.close(); 117 } 118 119 public static int selectFromSpecificSchema(int p1) throws SQLException { 120 Connection conn = DriverManager.getConnection("jdbc:default:connection"); 121 PreparedStatement ps = conn.prepareStatement("select * from mamta1.t12RoutineTest"); 122 ps.executeQuery(); 123 ps.close(); 124 conn.close(); 125 return (1); 126 } 127 128 private static void insertInBig(Connection conn, String A, String B, String C, String D) throws SQLException { 129 PreparedStatement ps = conn.prepareStatement("insert into big values (?, ?, ?, ?)"); 130 ps.setString(1, A); 131 ps.setString(2, B); 132 ps.setString(3, C); 133 ps.setString(4, D); 134 ps.executeUpdate(); 135 ps.close(); 136 } 137 138 public static void bigTestData(int i) throws SQLException { 139 Connection conn = DriverManager.getConnection("jdbc:default:connection"); 140 switch (i) 141 { 142 case 1: 143 String largeStringA10000 = new String (Formatters.repeatChar("a",10000)); 144 String largeStringB10000 = new String (Formatters.repeatChar("b",10000)); 145 String largeStringC10000 = new String (Formatters.repeatChar("c",10000)); 146 String largeStringD10000 = new String (Formatters.repeatChar("d",10000)); 147 insertInBig(conn, largeStringA10000, largeStringB10000, largeStringC10000, largeStringD10000); 148 break; 149 case 2: 150 largeStringA10000 = new String (Formatters.repeatChar("e",10000)); 151 largeStringB10000 = new String (Formatters.repeatChar("f",10000)); 152 largeStringC10000 = new String (Formatters.repeatChar("g",10000)); 153 largeStringD10000 = new String (Formatters.repeatChar("h",10000)); 154 insertInBig(conn, largeStringA10000, largeStringB10000, largeStringC10000, largeStringD10000); 155 break; 156 case 3: 157 largeStringA10000 = new String (Formatters.repeatChar("i",10000)); 158 largeStringB10000 = new String (Formatters.repeatChar("j",10000)); 159 largeStringC10000 = new String (Formatters.repeatChar("k",10000)); 160 largeStringD10000 = new String (Formatters.repeatChar("l",10000)); 161 insertInBig(conn, largeStringA10000, largeStringB10000, largeStringC10000, largeStringD10000); 162 break; 163 case 4: 164 largeStringA10000 = new String (Formatters.repeatChar("m",10000)); 165 largeStringB10000 = new String (Formatters.repeatChar("n",10000)); 166 largeStringC10000 = new String (Formatters.repeatChar("o",10000)); 167 largeStringD10000 = new String (Formatters.repeatChar("p",10000)); 168 insertInBig(conn, largeStringA10000, largeStringB10000, largeStringC10000, largeStringD10000); 169 break; 170 case 5: 171 String largeStringA30000 = new String (Formatters.repeatChar("a",30000)); 172 String largeStringB2752 = new String (Formatters.repeatChar("b",2752)); 173 PreparedStatement ps = conn.prepareStatement("insert into big values (?, ?)"); 174 ps.setString(1, largeStringA30000); 175 ps.setString(2, largeStringB2752); 176 ps.executeUpdate(); 177 ps.close(); 178 break; 179 case 6: 180 largeStringA30000 = new String (Formatters.repeatChar("a",30000)); 181 String largeStringB2750 = new String (Formatters.repeatChar("b",2750)); 182 ps = conn.prepareStatement("insert into big values (?, ?)"); 183 ps.setString(1, largeStringA30000); 184 ps.setString(2, largeStringB2750); 185 ps.executeUpdate(); 186 ps.close(); 187 break; 188 case 7: 189 String largeStringA40000 = new String (Formatters.repeatChar("a",40000)); 190 ps = conn.prepareStatement("insert into big values (?)"); 191 ps.setString(1, largeStringA40000); 192 ps.executeUpdate(); 193 ps.close(); 194 break; 195 case 8: 196 largeStringA40000 = new String (Formatters.repeatChar("a",40000)); 197 String largeStringB40000 = new String (Formatters.repeatChar("b",40000)); 198 String largeStringC40000 = new String (Formatters.repeatChar("c",40000)); 199 ps = conn.prepareStatement("insert into big values (?, ?, ?)"); 200 ps.setString(1, largeStringA40000); 201 ps.setString(2, largeStringB40000); 202 ps.setString(3, largeStringC40000); 203 ps.executeUpdate(); 204 largeStringA40000 = new String (Formatters.repeatChar("d",40000)); 205 largeStringB40000 = new String (Formatters.repeatChar("e",40000)); 206 largeStringC40000 = new String (Formatters.repeatChar("f",40000)); 207 ps.setString(1, largeStringA40000); 208 ps.setString(2, largeStringB40000); 209 ps.setString(3, largeStringC40000); 210 ps.executeUpdate(); 211 ps.close(); 212 break; 213 case 9: 214 String lStringA32672 = new String (Formatters.repeatChar("a",32672)); 215 String lStringB32672 = new String (Formatters.repeatChar("b",32672)); 216 String lStringC32672 = new String (Formatters.repeatChar("c",32672)); 217 String lStringD32672 = new String (Formatters.repeatChar("d",32672)); 218 insertInBig(conn, lStringA32672, lStringB32672, lStringC32672, lStringD32672); 219 break; 220 } 221 conn.close(); 222 } 223 224 226 231 public static void selectRows(int p1, ResultSet[] data) throws SQLException { 232 233 System.out.println("selectRows - 1 arg - 1 rs"); 234 235 Connection conn = DriverManager.getConnection("jdbc:default:connection"); 236 PreparedStatement ps = conn.prepareStatement("select * from t1 where i = ?"); 237 ps.setInt(1, p1); 238 data[0] = ps.executeQuery(); 239 conn.close(); 240 } 241 public static void selectRows(int p1, int p2, ResultSet[] data1, ResultSet[] data2) throws SQLException { 242 243 System.out.println("selectRows - 2 arg - 2 rs"); 244 245 Connection conn = DriverManager.getConnection("jdbc:default:connection"); 246 PreparedStatement ps = conn.prepareStatement("select * from t1 where i = ?"); 247 ps.setInt(1, p1); 248 data1[0] = ps.executeQuery(); 249 250 ps = conn.prepareStatement("select * from t1 where i >= ?"); 251 ps.setInt(1, p2); 252 data2[0] = ps.executeQuery(); 253 254 if (p2 == 99) 255 data2[0].close(); 256 257 if (p2 == 199) { 259 data1[0].close(); 260 data1[0] = null; 261 data2[0].close(); 262 data2[0] = null; 263 } 264 265 if (p2 == 299) { 267 ResultSet rs = data1[0]; 268 data1[0] = data2[0]; 269 data2[0] = rs; 270 } 271 272 conn.close(); 273 } 274 275 public static void selectRows(String table, ResultSet[] rs) 277 throws SQLException 278 { 279 Connection conn = DriverManager.getConnection("jdbc:default:connection"); 280 Statement stmt = conn.createStatement(); 281 rs[0] = stmt.executeQuery("SELECT * FROM " + table); 282 conn.close(); 283 } 284 285 public static void fivejp(ResultSet[] data1, ResultSet[] data2, ResultSet[] data3, ResultSet[] data4, ResultSet[] data5) throws SQLException { 286 287 Connection conn = DriverManager.getConnection("jdbc:default:connection"); 288 289 PreparedStatement ps1 = conn.prepareStatement("select * from MRS.FIVERS where i > ?"); 290 ps1.setInt(1, 1); 291 data1[0] = ps1.executeQuery(); 292 293 PreparedStatement ps2 = conn.prepareStatement("select * from MRS.FIVERS where i > ?"); 294 ps2.setInt(1, 2); 295 data2[0] = ps2.executeQuery(); 296 297 PreparedStatement ps3 = conn.prepareStatement("select * from MRS.FIVERS where i > ?"); 298 ps3.setInt(1, 3); 299 data3[0] = ps3.executeQuery(); 300 301 PreparedStatement ps4 = conn.prepareStatement("select * from MRS.FIVERS where i > ?"); 302 ps4.setInt(1, 4); 303 data4[0] = ps4.executeQuery(); 304 305 PreparedStatement ps5 = conn.prepareStatement("select * from MRS.FIVERS where i > ?"); 306 ps5.setInt(1, 5); 307 data5[0] = ps5.executeQuery(); 308 309 conn.close(); 310 } 311 312 public static void parameter1(int a, String b, String c, java.sql.ResultSet [] rs) throws SQLException { 313 314 System.out.print("PT1 a=" + a); 315 if (b == null) 316 System.out.println(" b = null"); 317 else 318 System.out.print(" b=<"+b+">("+b.length()+")"); 319 if (c == null) 320 System.out.println(" c = null"); 321 else 322 System.out.print(" c=<"+c+">("+c.length()+")"); 323 324 System.out.println(""); 325 326 327 328 Connection conn = DriverManager.getConnection("jdbc:default:connection"); 329 PreparedStatement ps = conn.prepareStatement("insert into PT1 values (?, ?, ?)"); 330 ps.setInt(1, a); 331 ps.setString(2, b); 332 ps.setString(3, c); 333 ps.executeUpdate(); 334 ps.close(); 335 ps = conn.prepareStatement("select a,b, length(b), c, length(c) from PT1 where a = ?"); 336 ps.setInt(1, a); 337 rs[0] = ps.executeQuery(); 338 conn.close(); 339 } 340 341 public static void parameter2(int a, java.math.BigDecimal b, java.math.BigDecimal c, java.sql.ResultSet [] rs) throws SQLException { 342 Connection conn = DriverManager.getConnection("jdbc:default:connection"); 343 PreparedStatement ps = conn.prepareStatement("insert into PT1 values (?, ?, ?)"); 344 ps.setInt(1, a); 345 ps.setString(2, b.toString()); 346 ps.setString(3, c.toString()); 347 ps.executeUpdate(); 348 ps.close(); 349 ps = conn.prepareStatement("select a,b,c from PT1 where a = ?"); 350 ps.setInt(1, a); 351 rs[0] = ps.executeQuery(); 352 conn.close(); 353 } 354 355 356 public static void outparams1(int[] p1, int p2) { 357 358 p1[0] = p2 * 2; 359 } 360 361 public static void clobselect (ResultSet[] results, 363 ResultSet[] results1, 364 ResultSet[] results2 365 ) 366 throws Exception 367 { 368 369 Connection conn = DriverManager.getConnection( 370 "jdbc:default:connection"); 371 PreparedStatement st = conn.prepareStatement("select * from lobCheckOne"); 372 results[0] = st.executeQuery(); 373 PreparedStatement st1 = conn.prepareStatement("select count(*) from lobCheckOne"); 375 results1[0] = st1.executeQuery(); 376 PreparedStatement st2 = conn.prepareStatement("select * from lobCheckOne"); 378 results2[0] = st2.executeQuery(); 379 conn.close(); 380 return; 381 382 } 383 384 public static void blobselect (ResultSet[] results) 386 throws Exception 387 { 388 389 Connection conn = DriverManager.getConnection( 390 "jdbc:default:connection"); 391 PreparedStatement st = conn.prepareStatement("select * from lobCheckTwo"); 392 results[0] = st.executeQuery(); 393 conn.close(); 394 return; 395 396 } 397 398 public static void inoutparams2(int[] p1, int p2) { 399 400 p1[0] = p1[0] + (p2 * 2); 401 } 402 public static void inoutparams3(String [] p1, int p2) { 403 404 if (p1[0] == null) 405 System.out.println("p1 is NULL"); 406 else 407 System.out.println("p1= >" + p1[0] + "< length " + p1[0].length()); 408 409 if (p2 == 8) 410 p1[0] = "nad"; 411 else if (p2 == 9) 412 p1[0] = null; 413 else if (p2 == 10) 414 p1[0] = "abcdefghijklmnopqrstuvwzyz"; 415 } 416 public static void inoutparams4(java.math.BigDecimal [] p1, String p2) { 417 if (p2 == null) 418 p1[0] = null; 419 else { 420 if (p1[0] == null) 421 p1[0] = new BigDecimal (p2).add(new BigDecimal ("17")); 422 else 423 p1[0] = new BigDecimal (p2).add(p1[0]); 424 } 425 } 426 427 public static void ambigious1(int p1, String p2, ResultSet[] data1, ResultSet[] data2) {} 428 public static void ambigious1(int p1, String p2, ResultSet[] data1) {} 429 430 431 public static void ambigious2(int p1, Integer p2) { 432 System.out.println("ambigious2(int,Integer) called"); 433 }; 434 public static void ambigious2(Integer p1, int p2) { 435 System.out.println("ambigious2(Integer,int) called"); 436 }; 437 438 public static void missingDynamicParameter(int p1) {} 439 public static void missingDynamicParameter(int p1, Object p2) {} 440 441 public static void badDynamicParameter(int p1, ProcedureTest[] data) {} 442 443 public static void zeroArgDynamicResult(ResultSet[] data1, ResultSet[] data2, ResultSet[] data3, ResultSet[] data4) { 444 System.out.println("zeroArgDynamicResult called"); 445 } 446 447 448 public static void sqlControl(String [] e1, String [] e2, String [] e3, String [] e4, String [] e5, String [] e6, String [] e7) 449 throws SQLException { 450 451 Connection conn = DriverManager.getConnection("jdbc:default:connection"); 452 453 Statement s = conn.createStatement(); 454 455 executeStatement(s, "CREATE TABLE SQLCONTROL_DDL (I INT)", e1); 456 executeStatement(s, "ALTER TABLE SQLC.SQLCONTROL_DML ADD COLUMN B INT DEFAULT NULL", e2); 457 458 executeStatement(s, "INSERT INTO SQLC.SQLCONTROL_DML(I) VALUES (1)", e3); 459 executeStatement(s, "UPDATE SQLC.SQLCONTROL_DML SET I = I + 11", e4); 460 executeStatement(s, "SELECT * FROM SQLC.SQLCONTROL_DML", e5); 461 executeStatement(s, "DELETE FROM SQLC.SQLCONTROL_DML", e6); 462 463 executeStatement(s, "DROP TABLE SQLC.SQLCONTROL_DML", e7); 464 465 conn.close(); 466 467 } 468 public static void sqlControl2(String [] e1, String [] e2, String [] e3, String [] e4, String [] e5, String [] e6, String [] e7) 469 throws SQLException { 470 471 Connection conn = DriverManager.getConnection("jdbc:default:connection"); 472 473 Statement s = conn.createStatement(); 474 475 executeStatement(s, "CREATE VIEW SQLCONTROL_VIEW AS SELECT * FROM SQLC.SQLCONTROL_DML", e1); 476 executeStatement(s, "DROP VIEW SQLCONTROL_VIEW", e2); 477 478 executeStatement(s, "LOCK TABLE SQLC.SQLCONTROL_DML IN EXCLUSIVE MODE", e3); 479 executeStatement(s, "VALUES 1,2,3", e4); 480 executeStatement(s, "SET SCHEMA SQLC", e5); 481 executeStatement(s, "CREATE SCHEMA SQLC_M", e6); 482 executeStatement(s, "DROP SCHEMA SQLC_M RESTRICT", e7); 483 484 conn.close(); 485 486 } 487 public static void sqlControl3(String [] e1, String [] e2, String [] e3, String [] e4, String [] e5, String [] e6, String [] e7) 488 throws SQLException { 489 490 Connection conn = DriverManager.getConnection("jdbc:default:connection"); 491 492 Statement s = conn.createStatement(); 493 494 e1[0] = "IBM CS FEATURE"; 495 e2[0] = "IBM CS FEATURE"; 496 497 executeStatement(s, "SET ISOLATION CS", e3); 498 executeStatement(s, "SET RUNTIMESTATISTICS OFF", e4); 499 executeStatement(s, "SET STATISTICS TIMING OFF", e5); 500 executeStatement(s, "VALUES 1", e6); 501 502 executeStatement(s, "VALUES 1", e7); 503 504 conn.close(); 505 506 } 507 public static void sqlControl4(int sqlc, String [] e1, String [] e2, String [] e3, String [] e4, String [] e5, String [] e6, String [] e7, String [] e8) 508 throws SQLException { 509 510 Connection conn = DriverManager.getConnection("jdbc:default:connection"); 511 512 Statement s = conn.createStatement(); 513 514 String sql = "CALL SQLC.SQLCONTROL2_"+sqlc+" (?, ?, ?, ?, ?, ?, ?) "; 515 516 e1[0] = sql; 517 518 CallableStatement cs1 = conn.prepareCall(sql); 519 try { 520 for (int rop = 1; rop <= 7; rop++) { 521 cs1.registerOutParameter(rop, Types.VARCHAR); 522 } 523 cs1.execute(); 524 525 e2[0] = cs1.getString(1); 526 e3[0] = cs1.getString(2); 527 e4[0] = cs1.getString(3); 528 e5[0] = cs1.getString(4); 529 e6[0] = cs1.getString(5); 530 e7[0] = cs1.getString(6); 531 e8[0] = cs1.getString(7); 532 } catch (SQLException sqle) { 533 StringBuffer sb = new StringBuffer (128); 534 sb.append("STATE"); 535 do { 536 sb.append("-"); 537 String ss = sqle.getSQLState(); 538 if (ss == null) 539 ss= "?????"; 540 sb.append(ss); 541 sqle = sqle.getNextException(); 542 } while (sqle != null); 543 e2[0] = sb.toString(); 544 } 545 546 cs1.close(); 547 548 conn.close(); 549 550 } 551 private static void executeStatement(Statement s, String sql, String [] result) { 552 553 StringBuffer sb = new StringBuffer (128); 554 555 int len = sql.length(); 556 if (len > 15) 557 len = 15; 558 559 sb.append(sql.substring(0, len)); 560 try { 561 if (s.execute(sql)) { 562 ResultSet rs = s.getResultSet(); 563 while (rs.next()) 564 sb.append("- ROW(" + rs.getString(1) + ")"); 565 rs.close(); 566 } else { 567 sb.append("-UPDATE " + s.getUpdateCount()); 568 } 569 570 sb.append("-EXECUTE OK"); 571 572 } catch (SQLException sqle) { 573 574 575 do { 576 sb.append("-"); 577 String ss = sqle.getSQLState(); 578 if (ss == null) 579 ss= "?????"; 580 sb.append(ss); 581 sqle = sqle.getNextException(); 582 } while (sqle != null); 583 584 585 } 586 result[0] = sb.toString(); 587 } 588 589 590 public static void oBOOLEAN(Boolean in, Boolean [] inout, Boolean [] out) throws SQLException { 591 592 if (out[0] != null) 593 throw new SQLException ("oBOOLEAN expected out[] to be null"); 594 595 out[0] = in; 596 if (in == null) 597 inout[0] = null; 598 else 599 inout[0] = new Boolean (inout[0].booleanValue() && in.booleanValue()); 600 601 } 602 603 public static void pBOOLEAN(boolean in, boolean[] inout, boolean[] out) throws SQLException { 604 605 if (out[0] != false) 606 throw new SQLException ("pBOOLEAN expected out[] to be null"); 607 608 out[0] = in; 609 inout[0] =inout[0] && in; 610 611 } 612 public static void oALLINT(Integer in, Integer [] inout, Integer [] out) throws SQLException { 613 614 if (out[0] != null) 615 throw new SQLException ("oALLINT expected out[] to be null"); 616 617 out[0] = in; 618 if (in == null) 619 ; else if (inout[0] == null) 621 inout[0] = new Integer (3 * in.intValue()); 622 else 623 inout[0] = new Integer (inout[0].intValue() + in.intValue()); 624 } 625 public static void pTINYINT(byte in, byte[] inout, byte[] out) throws SQLException { 626 627 out[0] = in; 628 inout[0] += in; 629 } 630 public static void pSMALLINT(short in, short[] inout, short[] out) throws SQLException { 631 632 out[0] = in; 633 inout[0] += in; 634 } 635 636 639 640 public static void literalTest(int p1, String [] p2) { 641 p2[0] = ">" + Integer.toString(p1) + "<"; 642 } 643 public static void literalTest(long p1, String [] p2) { 644 p2[0] = ">" + Long.toString(p1) + "<"; 645 } 646 public static void literalTest(float p1, String [] p2) { 647 p2[0] = ">" + Float.toString(p1) + "<"; 648 } 649 public static void literalTest(double p1, String [] p2) { 650 p2[0] = ">" + Double.toString(p1) + "<"; 651 } 652 public static void literalTest(BigDecimal p1, String [] p2) { 653 String s = p1 == null ? "NULL" : p1.toString(); 654 p2[0] = ">" + s + "<"; 655 } 656 public static void literalTest(String p1, String [] p2) { 657 String s = p1 == null ? "NULL" : p1.toString(); 658 p2[0] = ">" + s + "<"; 659 } 660 public static void literalTest(java.sql.Date p1, String [] p2) { 661 String s = p1 == null ? "NULL" : p1.toString(); 662 p2[0] = ">" + s + "<"; 663 } 664 public static void literalTest(java.sql.Time p1, String [] p2) { 665 String s = p1 == null ? "NULL" : p1.toString(); 666 p2[0] = ">" + s + "<"; 667 } 668 public static void literalTest(java.sql.Timestamp p1, String [] p2) { 669 670 String s = p1 == null ? "NULL" : p1.toString(); 671 p2[0] = ">" + s + "<"; 672 } 673 674 675 678 679 public static void pmap(BigDecimal in, BigDecimal [] inout, BigDecimal [] out) { 680 inout[0] = inout[0].add(new BigDecimal (2.3)); 681 out[0] = new BigDecimal (84.1); 682 } 683 684 public static int countRows(String schema, String table) throws SQLException 685 { 686 Connection conn = DriverManager.getConnection("jdbc:default:connection"); 687 Statement s = conn.createStatement(); 688 ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM " + schema + "." + table); 689 rs.next(); 690 int count = rs.getInt(1); 691 rs.close(); 692 s.close(); 693 conn.close(); 694 return count; 695 } 696 697 707 public static void multiResult(int p1, int p2, ResultSet[] data1, ResultSet[] data2) 708 throws SQLException { 709 710 Connection conn = DriverManager.getConnection("jdbc:default:connection"); 711 PreparedStatement ps = conn.prepareStatement("select * from AutoCommitTable where num = ?"); 712 ps.setInt(1, p1); 713 data1[0] = ps.executeQuery(); 714 715 ps = conn.prepareStatement("select * from AutoCommitTable where num = ?"); 716 ps.setInt(1, p2); 717 data2[0] = ps.executeQuery(); 718 719 conn.close(); 720 } 721 722 725 public static void BIG_COL_491 (int i, ResultSet [] rs1, ResultSet [] rs2) 726 throws SQLException 727 { 728 Connection conn = DriverManager.getConnection("jdbc:default:connection"); 729 Statement st1 = conn.createStatement(); 730 rs1[0] = st1.executeQuery( 731 "select int1, varchar32k from jira491 where int1 < " + i + " order by 1"); 732 733 Statement st2 = conn.createStatement(); 734 rs2[0] = st2.executeQuery( 735 "select int1, varchar32k from jira491 where int1 > " + i + " order by 1"); 736 } 737 738 741 public static void LOTS_O_COLS_492(ResultSet [] rs) 742 throws SQLException 743 { 744 Connection conn = DriverManager.getConnection("jdbc:default:connection"); 745 Statement st1 = conn.createStatement(); 746 747 StringBuffer query = new StringBuffer ("SELECT "); 748 for (int i = 0; i < 100; i++) 749 { 750 int cno = 1000 + (i * 10); 751 if (i > 0) query.append(", "); 752 query.append("id AS col").append(cno).append(", nsi as col"). 753 append(cno+1).append(", ni AS col").append(cno+2). 754 append(", nbi AS col").append(cno+3).append(", nd AS col"). 755 append(cno+4).append(", nr AS col").append(cno+5). 756 append(", ndo AS col").append(cno+6).append(" "); 757 } 758 query.append("FROM jira492 a WHERE a.id = 0"); 759 760 rs[0] = st1.executeQuery(query.toString()); 761 } 762 763 public static void grantSelect() throws SQLException 764 { 765 Connection conn = DriverManager.getConnection("jdbc:default:connection"); 766 PreparedStatement ps = conn.prepareStatement("grant select on t1 to user2"); 767 ps.execute(); 768 ps.close(); 769 conn.close(); 770 } 771 772 public static void revokeSelect() throws SQLException 773 { 774 Connection conn = DriverManager.getConnection("jdbc:default:connection"); 775 PreparedStatement ps = conn.prepareStatement("revoke select on t1 from user2"); 776 ps.execute(); 777 ps.close(); 778 conn.close(); 779 } 780 } 781 782 | Popular Tags |