0001: /*
0002:
0003: Derby - Class org.apache.derbyTesting.functionTests.tests.jdbcapi.autoGeneratedJdbc30
0004:
0005: Licensed to the Apache Software Foundation (ASF) under one or more
0006: contributor license agreements. See the NOTICE file distributed with
0007: this work for additional information regarding copyright ownership.
0008: The ASF licenses this file to You under the Apache License, Version 2.0
0009: (the "License"); you may not use this file except in compliance with
0010: the License. You may obtain a copy of the License at
0011:
0012: http://www.apache.org/licenses/LICENSE-2.0
0013:
0014: Unless required by applicable law or agreed to in writing, software
0015: distributed under the License is distributed on an "AS IS" BASIS,
0016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0017: See the License for the specific language governing permissions and
0018: limitations under the License.
0019:
0020: */
0021:
0022: package org.apache.derbyTesting.functionTests.tests.jdbcapi;
0023:
0024: import java.sql.Connection;
0025: import java.sql.DriverManager;
0026: import java.sql.PreparedStatement;
0027: import java.sql.ResultSet;
0028: import java.sql.ResultSetMetaData;
0029: import java.sql.Savepoint;
0030: import java.sql.Statement;
0031: import java.sql.SQLException;
0032:
0033: import org.apache.derby.tools.ij;
0034: import org.apache.derby.tools.JDBCDisplayUtil;
0035:
0036: import org.apache.derbyTesting.functionTests.util.TestUtil;
0037:
0038: /**
0039: * Test the new Auto Generated Keys feature in jdbc 30 for Statement and PreparedStatement.
0040: *
0041: * @author mamta
0042: */
0043:
0044: public class autoGeneratedJdbc30 {
0045:
0046: private static String[] testObjects = { "table t11", "table t21",
0047: "table t31" };
0048:
0049: private static boolean HAVE_DRIVER_MANAGER_CLASS;
0050:
0051: static {
0052: try {
0053: Class.forName("java.sql.DriverManager");
0054: HAVE_DRIVER_MANAGER_CLASS = true;
0055: } catch (ClassNotFoundException e) {
0056: //Used for JSR169
0057: HAVE_DRIVER_MANAGER_CLASS = false;
0058: }
0059: }
0060:
0061: public static void main(String[] args) {
0062:
0063: Connection con = null;
0064: Statement s;
0065: PreparedStatement ps;
0066:
0067: System.out.println("Test autoGeneratedJdbc30 starting");
0068:
0069: try {
0070: ij.getPropertyArg(args);
0071: con = ij.startJBMS();
0072:
0073: s = con.createStatement();
0074: /* Create the tables and do any other set-up */
0075: setUpTest(s);
0076: con.setAutoCommit(false);
0077:
0078: positiveTests(con);
0079:
0080: if (HAVE_DRIVER_MANAGER_CLASS)
0081: doTest1920(s, con);
0082:
0083: negativeTests(con);
0084:
0085: s = con.createStatement();
0086: TestUtil.cleanUpTest(s, testObjects);
0087: con.commit();
0088: con.close();
0089: } catch (SQLException e) {
0090: JDBCDisplayUtil.ShowSQLException(System.out, e);
0091: } catch (Throwable e) {
0092: System.out.println("FAIL -- unexpected exception:");
0093: e.printStackTrace(System.out);
0094: }
0095:
0096: System.out.println("Test autoGeneratedJdbc30 finished");
0097: }
0098:
0099: public static String MyMethodWithNoInsert() throws SQLException {
0100: System.out
0101: .println("Inside server-side method with no insert statement");
0102: Connection conn = DriverManager
0103: .getConnection("jdbc:default:connection");
0104: Statement s = conn.createStatement();
0105: s.executeQuery("select * from t11");
0106: return "true";
0107: }
0108:
0109: public static String MyMethodWithInsert() throws SQLException {
0110: System.out
0111: .println("Inside server-side method with couple insert statement with various combination of auto generated keys flag");
0112: Connection conn = DriverManager
0113: .getConnection("jdbc:default:connection");
0114: Statement s = conn.createStatement();
0115: s.execute("insert into t11(c11) values(999)",
0116: Statement.RETURN_GENERATED_KEYS);
0117: dumpRS(s.getGeneratedKeys());
0118: s.execute("insert into t11(c11) values(999)",
0119: Statement.NO_GENERATED_KEYS);
0120: try {
0121: dumpRS(s.getGeneratedKeys());
0122: } catch (SQLException e) {
0123: dumpExpectedSQLExceptions(e);
0124: }
0125: dumpRS(s.executeQuery("select * from t11"));
0126: return "true";
0127: }
0128:
0129: public static int count(Connection con, Statement s)
0130: throws SQLException {
0131: int count = 0;
0132: ResultSet rs = s.executeQuery("select count(*) from t11");
0133: rs.next();
0134: count = rs.getInt(1);
0135: rs.close();
0136: return count;
0137: }
0138:
0139: //Set up the test by creating the table used by the rest of the test.
0140: public static void setUpTest(Statement s) throws SQLException {
0141: try {
0142: // first drop to make sure there's nothing there
0143: s.execute("drop table t11");
0144: s.execute("drop table t21");
0145: s.execute("drop table t31");
0146: } catch (SQLException se) {
0147: // assume failure because there really wasn't anything there
0148: }
0149:
0150: /* Create a table */
0151: // set by increment not yet supported for create table...
0152: // does not matter for purpose of this test.
0153: // s.execute("create table t11 (c11 int, c12 int default set increment by 1)");
0154: s
0155: .execute("create table t11 (c11 int, c12 int generated always as identity)");
0156: s.execute("alter table t11 alter c12 set increment by 1");
0157: s
0158: .execute("create table t21 (c21 int not null unique, c22 char(5))");
0159: s.execute("insert into t21 values(21, 'true')");
0160: s.execute("insert into t21 values(22, 'true')");
0161: s
0162: .execute("create table t31 (c31 int, c32 int generated always as identity, c33 int default 2)");
0163: s.execute("alter table t31 alter c32 set increment by 1");
0164: }
0165:
0166: public static void dumpExpectedSQLExceptions(SQLException se) {
0167: System.out.println("PASS -- expected exception");
0168: while (se != null) {
0169: System.out.println("SQLSTATE(" + se.getSQLState() + "): "
0170: + se.getMessage());
0171: se = se.getNextException();
0172: }
0173: }
0174:
0175: // lifted from the metadata test
0176: public static void dumpRS(ResultSet s) throws SQLException {
0177: if (s == null) {
0178: System.out.println("<NULL>");
0179: return;
0180: }
0181:
0182: ResultSetMetaData rsmd = s.getMetaData();
0183:
0184: // Get the number of columns in the result set
0185: int numCols = rsmd.getColumnCount();
0186:
0187: if (numCols <= 0) {
0188: System.out.println("(no columns!)");
0189: return;
0190: }
0191:
0192: StringBuffer heading = new StringBuffer("\t ");
0193: StringBuffer underline = new StringBuffer("\t ");
0194:
0195: int len;
0196: // Display column headings
0197: for (int i = 1; i <= numCols; i++) {
0198: if (i > 1) {
0199: heading.append(",");
0200: underline.append(" ");
0201: }
0202: len = heading.length();
0203: heading.append(rsmd.getColumnLabel(i));
0204: len = heading.length() - len;
0205: for (int j = len; j > 0; j--) {
0206: underline.append("-");
0207: }
0208: }
0209: System.out.println(heading.toString());
0210: System.out.println(underline.toString());
0211:
0212: StringBuffer row = new StringBuffer();
0213: // Display data, fetching until end of the result set
0214: while (s.next()) {
0215: row.append("\t{");
0216: // Loop through each column, getting the
0217: // column data and displaying
0218: for (int i = 1; i <= numCols; i++) {
0219: if (i > 1)
0220: row.append(",");
0221: row.append(s.getString(i));
0222: }
0223: row.append("}\n");
0224: }
0225: System.out.println(row.toString());
0226: s.close();
0227: }
0228:
0229: public static void disabledTestsBecauseOfBug5580(Statement s,
0230: Connection con, PreparedStatement ps) throws SQLException {
0231: // re-enable following test whenever bug 5580 fixed
0232: //Test11 - insert select with columnIndexes[] array - bug 5580
0233: System.out
0234: .println("Test11 - insert select with columnIndexes[] array");
0235: int colPositions[] = new int[1];
0236: colPositions[0] = 1;
0237: s.execute("insert into t11(c11) select c21 from t21",
0238: colPositions);
0239: dumpRS(s.getGeneratedKeys());
0240: s.executeUpdate("insert into t11(c11) select c21 from t21",
0241: colPositions);
0242: dumpRS(s.getGeneratedKeys());
0243:
0244: System.out
0245: .println("Test11ps - insert select with columnIndexes[] array");
0246: ps = con.prepareStatement(
0247: "insert into t11(c11) select c21 from t21",
0248: colPositions);
0249: ps.execute();
0250: dumpRS(ps.getGeneratedKeys());
0251: ps.executeUpdate();
0252: dumpRS(ps.getGeneratedKeys());
0253:
0254: // BUG 4836 Hey, actually fetch a generated column!!!!!!!!!!!!!
0255: colPositions[0] = 2;
0256: s.executeUpdate("insert into t11(c11) select c21 from t21",
0257: colPositions);
0258: try {
0259: dumpRS(s.getGeneratedKeys());
0260: } catch (SQLException e) {
0261: dumpExpectedSQLExceptions(e);
0262: }
0263: ps = con.prepareStatement(
0264: "insert into t11(c11) select c21 from t21",
0265: colPositions);
0266: ps.executeUpdate();
0267: dumpRS(ps.getGeneratedKeys());
0268:
0269: //Verify data in the table
0270: if (count(con, s) != 12) {
0271: System.out.println("Test failed");
0272: return;
0273: }
0274: s.execute("delete from t11");
0275:
0276: //Test12 - insert select with columnIndexes[] array with duplicate column positions
0277: System.out
0278: .println("Test12 - insert select with columnIndexes[] array with duplicate column positions");
0279: colPositions = new int[2];
0280: colPositions[0] = 1;
0281: colPositions[1] = 1;
0282: s.execute("insert into t11(c11) select c21 from t21",
0283: colPositions);
0284: dumpRS(s.getGeneratedKeys());
0285: s.executeUpdate("insert into t11(c11) select c21 from t21",
0286: colPositions);
0287: dumpRS(s.getGeneratedKeys());
0288:
0289: System.out
0290: .println("Test12ps - insert select with columnIndexes[] array with duplicate column positions");
0291: ps = con.prepareStatement(
0292: "insert into t11(c11) select c21 from t21",
0293: colPositions);
0294: ps.execute();
0295: dumpRS(ps.getGeneratedKeys());
0296: ps.executeUpdate();
0297: dumpRS(ps.getGeneratedKeys());
0298:
0299: //Verify data in the table
0300: if (count(con, s) != 8) {
0301: System.out.println("Test failed");
0302: return;
0303: }
0304: s.execute("delete from t11");
0305:
0306: //Test13 - insert select with columnIndexes[] array with invalid column position
0307: System.out
0308: .println("Test13 - insert select with columnIndexes[] array with invalid column position");
0309: colPositions[0] = 3;
0310: try {
0311: s.execute("insert into t11(c11) select c21 from t21",
0312: colPositions);
0313: } catch (SQLException e) {
0314: dumpExpectedSQLExceptions(e);
0315: }
0316: try {
0317: dumpRS(s.getGeneratedKeys());
0318: } catch (SQLException e) {
0319: dumpExpectedSQLExceptions(e);
0320: }
0321: try {
0322: s.executeUpdate("insert into t11(c11) select c21 from t21",
0323: colPositions);
0324: } catch (SQLException e) {
0325: dumpExpectedSQLExceptions(e);
0326: }
0327: try {
0328: dumpRS(s.getGeneratedKeys());
0329: } catch (SQLException e) {
0330: dumpExpectedSQLExceptions(e);
0331: }
0332:
0333: System.out
0334: .println("Test13ps - insert select with columnIndexes[] array with invalid column position");
0335: try {
0336: ps = con.prepareStatement(
0337: "insert into t11(c11) select c21 from t21",
0338: colPositions);
0339: ps.execute();
0340: } catch (SQLException e) {
0341: dumpExpectedSQLExceptions(e);
0342: }
0343: try {
0344: dumpRS(ps.getGeneratedKeys());
0345: } catch (SQLException e) {
0346: dumpExpectedSQLExceptions(e);
0347: }
0348: try {
0349: ps.executeUpdate();
0350: } catch (SQLException e) {
0351: dumpExpectedSQLExceptions(e);
0352: }
0353: try {
0354: dumpRS(ps.getGeneratedKeys());
0355: } catch (SQLException e) {
0356: dumpExpectedSQLExceptions(e);
0357: }
0358:
0359: //Verify data in the table
0360: if (count(con, s) != 0) {
0361: System.out.println("Test failed");
0362: return;
0363: }
0364: s.execute("delete from t11");
0365:
0366: //Test14 - insert select with columnNames[] array
0367: System.out
0368: .println("Test14 - insert select with columnNames[] array");
0369: String colNames[] = new String[1];
0370: colNames[0] = "C11";
0371: s.execute("insert into t11(c11) select c21 from t21", colNames);
0372: dumpRS(s.getGeneratedKeys());
0373: s.executeUpdate("insert into t11(c11) select c21 from t21",
0374: colNames);
0375: dumpRS(s.getGeneratedKeys());
0376:
0377: System.out
0378: .println("Test14ps - insert select with columnNames[] array");
0379: ps = con.prepareStatement(
0380: "insert into t11(c11) select c21 from t21", colNames);
0381: ps.execute();
0382: dumpRS(ps.getGeneratedKeys());
0383: ps.executeUpdate();
0384: dumpRS(ps.getGeneratedKeys());
0385:
0386: // BUG 4836 Hey, actually fetch a generated column!!!!!!!!!!!!!
0387: colNames[0] = "C12";
0388: s.executeUpdate("insert into t11(c11) select c21 from t21",
0389: colNames);
0390: dumpRS(s.getGeneratedKeys());
0391: ps = con.prepareStatement(
0392: "insert into t11(c11) select c21 from t21", colNames);
0393: ps.executeUpdate();
0394: dumpRS(ps.getGeneratedKeys());
0395:
0396: //Verify data in the table
0397: if (count(con, s) != 12) {
0398: System.out.println("Test failed");
0399: return;
0400: }
0401: s.execute("delete from t11");
0402:
0403: //Test15 - insert select with columnNames[] array with duplicate column names
0404: System.out
0405: .println("Test15 - insert select with columnNames[] array with duplicate column names");
0406: colNames = new String[2];
0407: colNames[0] = "C11";
0408: colNames[1] = "C11";
0409: s.execute("insert into t11(c11) select c21 from t21", colNames);
0410: dumpRS(s.getGeneratedKeys());
0411: s.executeUpdate("insert into t11(c11) select c21 from t21",
0412: colNames);
0413: dumpRS(s.getGeneratedKeys());
0414:
0415: System.out
0416: .println("Test15ps - insert select with columnNames[] array with duplicate column names");
0417: ps = con.prepareStatement(
0418: "insert into t11(c11) select c21 from t21", colNames);
0419: ps.execute();
0420: dumpRS(ps.getGeneratedKeys());
0421: ps.executeUpdate();
0422: dumpRS(ps.getGeneratedKeys());
0423:
0424: //Verify data in the table
0425: if (count(con, s) != 8) {
0426: System.out.println("Test failed");
0427: return;
0428: }
0429: s.execute("delete from t11");
0430:
0431: //Test16 - insert select with columnNames[] array with invalid column name
0432: colNames = new String[1];
0433: System.out
0434: .println("Test16 - insert select with columnNames[] array with invalid column name");
0435: colNames[0] = "C13";
0436: try {
0437: s.execute("insert into t11(c11) select c21 from t21",
0438: colNames);
0439: } catch (SQLException e) {
0440: dumpExpectedSQLExceptions(e);
0441: }
0442: try {
0443: dumpRS(s.getGeneratedKeys());
0444: } catch (SQLException e) {
0445: dumpExpectedSQLExceptions(e);
0446: }
0447: try {
0448: s.executeUpdate("insert into t11(c11) select c21 from t21",
0449: colNames);
0450: } catch (SQLException e) {
0451: dumpExpectedSQLExceptions(e);
0452: }
0453: try {
0454: dumpRS(s.getGeneratedKeys());
0455: } catch (SQLException e) {
0456: dumpExpectedSQLExceptions(e);
0457: }
0458:
0459: System.out
0460: .println("Test16ps - insert select with columnNames[] array with invalid column name");
0461: try {
0462: ps = con.prepareStatement(
0463: "insert into t11(c11) select c21 from t21",
0464: colNames);
0465: ps.execute();
0466: } catch (SQLException e) {
0467: dumpExpectedSQLExceptions(e);
0468: }
0469: try {
0470: dumpRS(ps.getGeneratedKeys());
0471: } catch (SQLException e) {
0472: dumpExpectedSQLExceptions(e);
0473: }
0474: try {
0475: ps.executeUpdate();
0476: } catch (SQLException e) {
0477: dumpExpectedSQLExceptions(e);
0478: }
0479: try {
0480: dumpRS(ps.getGeneratedKeys());
0481: } catch (SQLException e) {
0482: dumpExpectedSQLExceptions(e);
0483: }
0484:
0485: //Verify data in the table
0486: if (count(con, s) != 0) {
0487: System.out.println("Test failed");
0488: return;
0489: }
0490: s.execute("delete from t11");
0491:
0492: //Test17 - insert select with null columnIndexes[] internally switches to Statement.NO_GENERATED_KEYS
0493: System.out
0494: .println("Test17 - insert select with null columnIndexes[] internally switches to Statement.NO_GENERATED_KEYS");
0495: colPositions = null;
0496: s.execute("insert into t11(c11) select c21 from t21",
0497: colPositions);
0498: try {
0499: dumpRS(s.getGeneratedKeys());
0500: } catch (SQLException e) {
0501: dumpExpectedSQLExceptions(e);
0502: }
0503: s.executeUpdate("insert into t11(c11) select c21 from t21",
0504: colPositions);
0505: try {
0506: dumpRS(s.getGeneratedKeys());
0507: } catch (SQLException e) {
0508: dumpExpectedSQLExceptions(e);
0509: }
0510:
0511: System.out
0512: .println("Test17ps - insert select with null columnIndexes[] internally switches to Statement.NO_GENERATED_KEYS");
0513: ps = con.prepareStatement(
0514: "insert into t11(c11) select c21 from t21",
0515: colPositions);
0516: ps.execute();
0517: try {
0518: dumpRS(ps.getGeneratedKeys());
0519: } catch (SQLException e) {
0520: dumpExpectedSQLExceptions(e);
0521: }
0522: ps.executeUpdate();
0523: try {
0524: dumpRS(ps.getGeneratedKeys());
0525: } catch (SQLException e) {
0526: dumpExpectedSQLExceptions(e);
0527: }
0528:
0529: //Verify data in the table
0530: if (count(con, s) != 8) {
0531: System.out.println("Test failed");
0532: return;
0533: }
0534: s.execute("delete from t11");
0535:
0536: //Test18 - insert select with null columnNames[] internally switches to Statement.NO_GENERATED_KEYS
0537: System.out
0538: .println("Test18 - insert select with null columnNames[] internally switches to Statement.NO_GENERATED_KEYS");
0539: colNames = null;
0540: s.execute("insert into t11(c11) select c21 from t21", colNames);
0541: try {
0542: dumpRS(s.getGeneratedKeys());
0543: } catch (SQLException e) {
0544: dumpExpectedSQLExceptions(e);
0545: }
0546: s.executeUpdate("insert into t11(c11) select c21 from t21",
0547: colNames);
0548: try {
0549: dumpRS(s.getGeneratedKeys());
0550: } catch (SQLException e) {
0551: dumpExpectedSQLExceptions(e);
0552: }
0553:
0554: System.out
0555: .println("Test18ps - insert select with null columnNames[] internally switches to Statement.NO_GENERATED_KEYS");
0556: ps = con.prepareStatement(
0557: "insert into t11(c11) select c21 from t21", colNames);
0558: ps.execute();
0559: try {
0560: dumpRS(ps.getGeneratedKeys());
0561: } catch (SQLException e) {
0562: dumpExpectedSQLExceptions(e);
0563: }
0564: ps.executeUpdate();
0565: try {
0566: dumpRS(ps.getGeneratedKeys());
0567: } catch (SQLException e) {
0568: dumpExpectedSQLExceptions(e);
0569: }
0570:
0571: //Verify data in the table
0572: if (count(con, s) != 8) {
0573: System.out.println("Test failed");
0574: return;
0575: }
0576: s.execute("delete from t11");
0577:
0578: //Test19a - insert values with column position order which doesn't match column positions in the actual table
0579: //The column positions correspond to columns in the table and not the columns in the insert statement
0580: System.out
0581: .println("Test19a - insert values with column position order which doesn't match column positions in the actual table");
0582: colPositions = new int[1];
0583: colPositions[0] = 1;
0584: s.execute("insert into t21(c22,c21) values('true', 23)",
0585: colPositions);
0586: dumpRS(s.getGeneratedKeys());
0587: s.executeUpdate("insert into t21(c22,c21) values('true', 23)",
0588: colPositions);
0589: dumpRS(s.getGeneratedKeys());
0590:
0591: //Test19aps - insert values with column position order which doesn't match column positions in the actual table
0592: System.out
0593: .println("Test19aps - insert values with column position order which doesn't match column positions in the actual table");
0594: ps = con.prepareStatement(
0595: "insert into t21(c22,c21) values('true', 23)",
0596: colPositions);
0597: ps.execute();
0598: dumpRS(ps.getGeneratedKeys());
0599: ps.executeUpdate();
0600: dumpRS(ps.getGeneratedKeys());
0601:
0602: //Verify data in the table
0603: dumpRS(s.executeQuery("select count(*) from t21"));
0604: s.execute("delete from t11");
0605: }
0606:
0607: private static void positiveTests(Connection conn)
0608: throws SQLException {
0609: System.out
0610: .println("Test 1 - request for generated keys resultset on a brand new statement with no sql executed on it yet");
0611: System.out
0612: .println("We will get a resultset with no rows because it is a non-insert sql");
0613: Statement s = conn.createStatement();
0614: dumpRS(s.getGeneratedKeys());
0615:
0616: System.out
0617: .println("Test2 - request for generated keys on a statement which does select from a table ie a non-insert sql");
0618: s.execute("select * from t11", Statement.RETURN_GENERATED_KEYS);
0619: System.out
0620: .println("We will get a resultset with no rows because it is a non-insert sql");
0621: dumpRS(s.getGeneratedKeys());
0622: System.out
0623: .println("Now try the same test again but this time with PreparedStatement.execute. It should behave the same");
0624: PreparedStatement ps = conn.prepareStatement(
0625: "select * from t11", Statement.RETURN_GENERATED_KEYS);
0626: ps.execute();
0627: dumpRS(ps.getGeneratedKeys());
0628:
0629: System.out
0630: .println("Test 3 - insert multiple rows into a table with autogenerated key and request generated keys resultset");
0631: System.out
0632: .println(" We will get a row with NULL value because this insert sql inserted more than one row and ");
0633: System.out
0634: .println(" there was no prior one-row insert into a table with autogenerated key");
0635: s.execute("insert into t31(c31) values (99), (98), (97)",
0636: Statement.RETURN_GENERATED_KEYS);
0637: dumpRS(s.getGeneratedKeys());
0638: System.out
0639: .println("Now try the same test again but this time with Statement.executeUpdate. It should behave the same");
0640: s.executeUpdate("insert into t31(c31) values (99), (98), (97)",
0641: Statement.RETURN_GENERATED_KEYS);
0642: dumpRS(s.getGeneratedKeys());
0643: System.out
0644: .println("Now try the same test again but this time with PreparedStatement.execute. It should behave the same");
0645: ps = conn.prepareStatement(
0646: "insert into t31(c31) values (99), (98), (97)",
0647: Statement.RETURN_GENERATED_KEYS);
0648: ps.execute();
0649: dumpRS(ps.getGeneratedKeys());
0650: System.out
0651: .println("Now try the same test again but this time with PreparedStatement.executeUpdate. It should behave the same");
0652: ps.executeUpdate();
0653: dumpRS(ps.getGeneratedKeys());
0654:
0655: System.out
0656: .println("Test 4 - request for generated keys after doing an insert into a table with no auto generated keys");
0657: System.out
0658: .println(" And there has been no one-row insert into a table with auto-generated keys yet.");
0659: s.execute("insert into t21 values(23, 'true')",
0660: Statement.RETURN_GENERATED_KEYS);
0661: System.out
0662: .println("We should get a resultset with one row of NULL value from getGeneratedKeys");
0663: dumpRS(s.getGeneratedKeys());
0664: System.out
0665: .println("Now try the same test again but this time with Statement.executeUpdate. It should behave the same");
0666: s.executeUpdate("insert into t21 values(24, 'true')",
0667: Statement.RETURN_GENERATED_KEYS);
0668: dumpRS(s.getGeneratedKeys());
0669: System.out
0670: .println("Now try the same test again but this time with PreparedStatement.execute. It should behave the same");
0671: ps = conn.prepareStatement(
0672: "insert into t21 values(25, 'true')",
0673: Statement.RETURN_GENERATED_KEYS);
0674: ps.execute();
0675: dumpRS(ps.getGeneratedKeys());
0676: System.out
0677: .println("Now try the same test again but this time with PreparedStatement.executeUpdate. It should behave the same");
0678: ps = conn.prepareStatement(
0679: "insert into t21 values(26, 'true')",
0680: Statement.RETURN_GENERATED_KEYS);
0681: ps.executeUpdate();
0682: dumpRS(ps.getGeneratedKeys());
0683:
0684: System.out
0685: .println("Test 5a - request for generated keys after doing a one-row insert(using a subquery) into a table with autogenerated key using a subquery with auto generated keys");
0686: s.execute("insert into t11(c11) select c21 from t21",
0687: Statement.RETURN_GENERATED_KEYS);
0688: System.out
0689: .println("Even though this is a one-row insert but since insert has a sub-select, get generated keys will return one row of NULL value");
0690: dumpRS(s.getGeneratedKeys());
0691: System.out
0692: .println("Now try the same test again but this time with Statement.executeUpdate. It should behave the same");
0693: s.executeUpdate("insert into t11(c11) select c21 from t21",
0694: Statement.RETURN_GENERATED_KEYS);
0695: dumpRS(s.getGeneratedKeys());
0696: System.out
0697: .println("Now try the same test again but this time with PreparedStatement.execute. It should behave the same");
0698: ps = conn.prepareStatement(
0699: "insert into t11(c11) select c21 from t21",
0700: Statement.RETURN_GENERATED_KEYS);
0701: ps.execute();
0702: dumpRS(ps.getGeneratedKeys());
0703: System.out
0704: .println("Now try the same test again but this time with PreparedStatement.executeUpdate. It should behave the same");
0705: ps.executeUpdate();
0706: dumpRS(ps.getGeneratedKeys());
0707:
0708: System.out
0709: .println("Test 5b - request for generated keys after doing a one-row insert(using a subquery) into a table with autogenerated key using a subquery with auto generated keys");
0710: s.execute("insert into t11(c11) select c21 from t21 where 1=2",
0711: Statement.RETURN_GENERATED_KEYS);
0712: System.out
0713: .println("Even though this is a one-row insert but since insert has a sub-select, get generated keys will return one row of NULL value");
0714: dumpRS(s.getGeneratedKeys());
0715: System.out
0716: .println("Now try the same test again but this time with Statement.executeUpdate. It should behave the same");
0717: s.executeUpdate(
0718: "insert into t11(c11) select c21 from t21 where 1=2",
0719: Statement.RETURN_GENERATED_KEYS);
0720: dumpRS(s.getGeneratedKeys());
0721: System.out
0722: .println("Now try the same test again but this time with PreparedStatement.execute. It should behave the same");
0723: ps = conn.prepareStatement(
0724: "insert into t11(c11) select c21 from t21 where 1=2",
0725: Statement.RETURN_GENERATED_KEYS);
0726: ps.execute();
0727: dumpRS(ps.getGeneratedKeys());
0728: System.out
0729: .println("Now try the same test again but this time with PreparedStatement.executeUpdate. It should behave the same");
0730: ps.executeUpdate();
0731: dumpRS(ps.getGeneratedKeys());
0732:
0733: System.out
0734: .println("Test 5c - request for generated keys after doing a one-row insert(using a subquery) into a table with autogenerated key using a subquery with auto generated keys");
0735: s
0736: .execute(
0737: "insert into t11(c11) select c21 from t21 where c21=23",
0738: Statement.RETURN_GENERATED_KEYS);
0739: System.out
0740: .println("Even though this is a one-row insert but since insert has a sub-select, get generated keys will return one row of NULL value");
0741: dumpRS(s.getGeneratedKeys());
0742: System.out
0743: .println("Now try the same test again but this time with Statement.executeUpdate. It should behave the same");
0744: s
0745: .executeUpdate(
0746: "insert into t11(c11) select c21 from t21 where c21=23",
0747: Statement.RETURN_GENERATED_KEYS);
0748: dumpRS(s.getGeneratedKeys());
0749: System.out
0750: .println("Now try the same test again but this time with PreparedStatement.execute. It should behave the same");
0751: ps = conn
0752: .prepareStatement(
0753: "insert into t11(c11) select c21 from t21 where c21=23",
0754: Statement.RETURN_GENERATED_KEYS);
0755: ps.execute();
0756: dumpRS(ps.getGeneratedKeys());
0757: System.out
0758: .println("Now try the same test again but this time with PreparedStatement.executeUpdate. It should behave the same");
0759: ps.executeUpdate();
0760: dumpRS(ps.getGeneratedKeys());
0761:
0762: System.out
0763: .println("Test 6 - request for generated keys after doing a one-row insert into a table with auto generated keys");
0764: s.execute("insert into t11(c11) values (99)",
0765: Statement.RETURN_GENERATED_KEYS);
0766: System.out
0767: .println("We should get a resultset with one row of non-NULL value");
0768: dumpRS(s.getGeneratedKeys());
0769: System.out
0770: .println("Now try the same test again but this time with Statement.executeUpdate. It should behave the same");
0771: s.executeUpdate("insert into t11(c11) values (99)",
0772: Statement.RETURN_GENERATED_KEYS);
0773: dumpRS(s.getGeneratedKeys());
0774: System.out
0775: .println("Now try the same test again but this time with PreparedStatement.execute. It should behave the same");
0776: ps = conn.prepareStatement("insert into t11(c11) values (99)",
0777: Statement.RETURN_GENERATED_KEYS);
0778: ps.execute();
0779: dumpRS(ps.getGeneratedKeys());
0780: System.out
0781: .println("Now try the same test again but this time with PreparedStatement.executeUpdate. It should behave the same");
0782: ps.executeUpdate();
0783: dumpRS(ps.getGeneratedKeys());
0784:
0785: System.out
0786: .println("Test 7 - Now try again inserting multiple rows into a table with autogenerated key and request generated keys resultset");
0787: System.out
0788: .println(" This time we will get a row of non-NULL value because there has been a prior one-row insert into table with auto-generated key ");
0789: s.execute("insert into t31(c31) values (99), (98), (97)",
0790: Statement.RETURN_GENERATED_KEYS);
0791: dumpRS(s.getGeneratedKeys());
0792: System.out
0793: .println("Now try the same test again but this time with Statement.executeUpdate. It should behave the same");
0794: s.executeUpdate("insert into t31(c31) values (99), (98), (97)",
0795: Statement.RETURN_GENERATED_KEYS);
0796: dumpRS(s.getGeneratedKeys());
0797: System.out
0798: .println("Now try the same test again but this time with PreparedStatement.execute. It should behave the same");
0799: ps = conn.prepareStatement(
0800: "insert into t31(c31) values (99), (98), (97)",
0801: Statement.RETURN_GENERATED_KEYS);
0802: ps.execute();
0803: dumpRS(ps.getGeneratedKeys());
0804: System.out
0805: .println("Now try the same test again but this time with PreparedStatement.executeUpdate. It should behave the same");
0806: ps.executeUpdate();
0807: dumpRS(ps.getGeneratedKeys());
0808:
0809: System.out
0810: .println("Test 8 - create a new statement and request for generated keys on it after doing an insert into ");
0811: System.out.println(" a table with no auto generated keys");
0812: Statement s1 = conn.createStatement();
0813: s1.execute("insert into t21 values(27, 'true')",
0814: Statement.RETURN_GENERATED_KEYS);
0815: System.out
0816: .println("We should get a resultset with one row of non-NULL value");
0817: dumpRS(s1.getGeneratedKeys());
0818: System.out
0819: .println("Now try the same test again but this time with Statement.executeUpdate. It should behave the same");
0820: s1.executeUpdate("insert into t21 values(28, 'true')",
0821: Statement.RETURN_GENERATED_KEYS);
0822: dumpRS(s1.getGeneratedKeys());
0823: System.out
0824: .println("Now try the same test again but this time with PreparedStatement.execute. It should behave the same");
0825: ps = conn.prepareStatement(
0826: "insert into t21 values(29, 'true')",
0827: Statement.RETURN_GENERATED_KEYS);
0828: ps.execute();
0829: dumpRS(ps.getGeneratedKeys());
0830: System.out
0831: .println("Now try the same test again but this time with PreparedStatement.executeUpdate. It should behave the same");
0832: ps = conn.prepareStatement(
0833: "insert into t21 values(30, 'true')",
0834: Statement.RETURN_GENERATED_KEYS);
0835: ps.executeUpdate();
0836: dumpRS(ps.getGeneratedKeys());
0837:
0838: System.out
0839: .println("Test 9 - request for generated keys on a statement which does a update ");
0840: s.execute("update t11 set c11=1",
0841: Statement.RETURN_GENERATED_KEYS);
0842: System.out
0843: .println("We should get a resultset with no rows from getGeneratedKeys because we executed a non-insert sql");
0844: dumpRS(s.getGeneratedKeys());
0845: System.out
0846: .println("Now try the same test again but this time with Statement.executeUpdate. It should behave the same");
0847: s.executeUpdate("update t11 set c11=1",
0848: Statement.RETURN_GENERATED_KEYS);
0849: dumpRS(s.getGeneratedKeys());
0850: System.out
0851: .println("Now try the same test again but this time with PreparedStatement.execute. It should behave the same");
0852: ps = conn.prepareStatement("update t11 set c11=1",
0853: Statement.RETURN_GENERATED_KEYS);
0854: ps.execute();
0855: dumpRS(ps.getGeneratedKeys());
0856: System.out
0857: .println("Now try the same test again but this time with PreparedStatement.executeUpdate. It should behave the same");
0858: ps.executeUpdate();
0859: dumpRS(ps.getGeneratedKeys());
0860:
0861: System.out
0862: .println("Test 10 - request for generated keys on a statement which does a delete ");
0863: s.execute("delete from t11", Statement.RETURN_GENERATED_KEYS);
0864: System.out
0865: .println("We should get a resultset with no rows from getGeneratedKeys because we executed a non-insert sql");
0866: dumpRS(s.getGeneratedKeys());
0867: System.out
0868: .println("Now try the same test again but this time with Statement.executeUpdate. It should behave the same");
0869: s.executeUpdate("delete from t11",
0870: Statement.RETURN_GENERATED_KEYS);
0871: dumpRS(s.getGeneratedKeys());
0872: System.out
0873: .println("Now try the same test again but this time with PreparedStatement.execute. It should behave the same");
0874: ps = conn.prepareStatement("delete from t11",
0875: Statement.RETURN_GENERATED_KEYS);
0876: ps.execute();
0877: dumpRS(ps.getGeneratedKeys());
0878: System.out
0879: .println("Now try the same test again but this time with PreparedStatement.executeUpdate. It should behave the same");
0880: ps.executeUpdate();
0881: dumpRS(ps.getGeneratedKeys());
0882:
0883: System.out
0884: .println("Test 11 - do a commit and request for generated keys on a statement which does insert into a table with ");
0885: System.out
0886: .println(" no auto generated keys (previous transaction had a one-row insert on a table with auto-generated keys)");
0887: conn.commit();
0888: s.execute("insert into t21 values(31, 'true')",
0889: Statement.RETURN_GENERATED_KEYS);
0890: System.out
0891: .println("expected to see resultset with one row of NULL value but instead get one row of non-NULL value from getGeneratedKeys");
0892: dumpRS(s.getGeneratedKeys());
0893: System.out
0894: .println("Now try the same test again but this time with Statement.executeUpdate. It should behave the same");
0895: s.executeUpdate("insert into t21 values(32, 'true')",
0896: Statement.RETURN_GENERATED_KEYS);
0897: dumpRS(s.getGeneratedKeys());
0898: System.out
0899: .println("Now try the same test again but this time with PreparedStatement.execute. It should behave the same");
0900: ps = conn.prepareStatement(
0901: "insert into t21 values(33, 'true')",
0902: Statement.RETURN_GENERATED_KEYS);
0903: ps.execute();
0904: dumpRS(ps.getGeneratedKeys());
0905: System.out
0906: .println("Now try the same test again but this time with PreparedStatement.executeUpdate. It should behave the same");
0907: ps = conn.prepareStatement(
0908: "insert into t21 values(34, 'true')",
0909: Statement.RETURN_GENERATED_KEYS);
0910: ps.executeUpdate();
0911: dumpRS(ps.getGeneratedKeys());
0912:
0913: System.out
0914: .println("Test 12 - do a rollback and request for generated keys on a statement which does insert into a table with ");
0915: System.out
0916: .println(" no auto generated keys (previous transaction had a one-row insert on a table with auto-generated keys)");
0917: conn.rollback();
0918: s.execute("insert into t21 values(35, 'true')",
0919: Statement.RETURN_GENERATED_KEYS);
0920: System.out
0921: .println("had expected to see resultset with one row of NULL value but instead get one row of non-NULL value from getGeneratedKeys");
0922: dumpRS(s.getGeneratedKeys());
0923: System.out
0924: .println("Now try the same test again but this time with Statement.executeUpdate. It should behave the same");
0925: s.executeUpdate("insert into t21 values(36, 'true')",
0926: Statement.RETURN_GENERATED_KEYS);
0927: dumpRS(s.getGeneratedKeys());
0928: System.out
0929: .println("Now try the same test again but this time with PreparedStatement.execute. It should behave the same");
0930: ps = conn.prepareStatement(
0931: "insert into t21 values(37, 'true')",
0932: Statement.RETURN_GENERATED_KEYS);
0933: ps.execute();
0934: dumpRS(ps.getGeneratedKeys());
0935: System.out
0936: .println("Now try the same test again but this time with PreparedStatement.executeUpdate. It should behave the same");
0937: ps = conn.prepareStatement(
0938: "insert into t21 values(38, 'true')",
0939: Statement.RETURN_GENERATED_KEYS);
0940: ps.executeUpdate();
0941: dumpRS(ps.getGeneratedKeys());
0942:
0943: System.out
0944: .println("Test 13 - try savepoint rollback and see what happens to auto generated keys resultset");
0945: Savepoint savepoint1;
0946: System.out
0947: .println("Inside the savepoint unit, issue a one-row insert into a table with auto generated keys");
0948: savepoint1 = conn.setSavepoint();
0949: s.execute("insert into t11(c11) values (99)",
0950: Statement.RETURN_GENERATED_KEYS);
0951: System.out
0952: .println("We should get a resultset with one row of non-NULL value");
0953: dumpRS(s.getGeneratedKeys());
0954: System.out
0955: .println("Now rollback the savepoint unit, and make sure that autogenerated keys resultset still holds on to ");
0956: System.out
0957: .println(" value that got set inside the rolled back savepoint unit");
0958: conn.rollback(savepoint1);
0959: s.execute("insert into t21 values(39, 'true')",
0960: Statement.RETURN_GENERATED_KEYS);
0961: dumpRS(s.getGeneratedKeys());
0962:
0963: System.out
0964: .println("Test 14 - Look at metadata of a getGeneratedKeys resultset");
0965: s = conn.createStatement();
0966: s.execute("insert into t31(c31) values (99)",
0967: Statement.RETURN_GENERATED_KEYS);
0968: ResultSet rs = s.getGeneratedKeys();
0969: ResultSetMetaData rsmd = rs.getMetaData();
0970: System.out.println("The resultset will have one column only");
0971: System.out.println("Found " + rsmd.getColumnCount()
0972: + " column in the resultset");
0973: System.out.println("Type of the column is "
0974: + rsmd.getColumnTypeName(1));
0975: System.out.println("Precision of the column is "
0976: + rsmd.getPrecision(1));
0977: System.out
0978: .println("Scale of the column is " + rsmd.getScale(1));
0979: dumpRS(rs);
0980:
0981: System.out
0982: .println("Test 15 - Can not see the auto generated keys if insert is with NO_GENERATED_KEYS");
0983: s = conn.createStatement();
0984: s.execute("insert into t31(c31) values (99)",
0985: Statement.NO_GENERATED_KEYS);
0986: dumpRS(s.getGeneratedKeys());
0987: s.executeUpdate("insert into t31(c31) values (99)",
0988: Statement.NO_GENERATED_KEYS);
0989: dumpRS(s.getGeneratedKeys());
0990: ps = conn.prepareStatement("insert into t31(c31) values (99)",
0991: Statement.NO_GENERATED_KEYS);
0992: ps.execute();
0993: dumpRS(ps.getGeneratedKeys());
0994: ps.executeUpdate();
0995: dumpRS(ps.getGeneratedKeys());
0996:
0997: System.out
0998: .println("Test 16 - Can not see the auto generated keys if insert is done jdbc 2.0 way ie with no generated key feature");
0999: s.execute("insert into t31(c31) values (99)");
1000: dumpRS(s.getGeneratedKeys());
1001: s.executeUpdate("insert into t31(c31) values (99)");
1002: dumpRS(s.getGeneratedKeys());
1003: ps = conn.prepareStatement("insert into t31(c31) values (99)");
1004: ps.execute();
1005: dumpRS(ps.getGeneratedKeys());
1006: ps.executeUpdate();
1007: dumpRS(ps.getGeneratedKeys());
1008:
1009: System.out
1010: .println("Test 17 - non-insert with NO_GENERATED_KEYS");
1011: s = conn.createStatement();
1012: s.execute("update t31 set c31=98", Statement.NO_GENERATED_KEYS);
1013: dumpRS(s.getGeneratedKeys());
1014: s.executeUpdate("update t31 set c31=98",
1015: Statement.NO_GENERATED_KEYS);
1016: dumpRS(s.getGeneratedKeys());
1017: ps = conn.prepareStatement("update t31 set c31=98",
1018: Statement.NO_GENERATED_KEYS);
1019: ps.execute();
1020: dumpRS(ps.getGeneratedKeys());
1021: ps.executeUpdate();
1022: dumpRS(ps.getGeneratedKeys());
1023:
1024: System.out
1025: .println("Test 18 - non-insert is done jdbc 2.0 way ie with no generated key feature");
1026: s.execute("delete from t31");
1027: dumpRS(s.getGeneratedKeys());
1028: s.executeUpdate("delete from t31");
1029: dumpRS(s.getGeneratedKeys());
1030: ps = conn.prepareStatement("delete from t31");
1031: ps.execute();
1032: dumpRS(ps.getGeneratedKeys());
1033: ps.executeUpdate();
1034: dumpRS(ps.getGeneratedKeys());
1035:
1036: }
1037:
1038: public static void negativeTests(Connection con)
1039: throws SQLException {
1040: Statement s = con.createStatement();
1041: PreparedStatement ps;
1042: //Test21 - insert select with columnIndexes[] array
1043: System.out
1044: .println("Test21 - insert select with columnIndexes[] array should fail");
1045: int colPositions[] = new int[1];
1046: colPositions[0] = 1;
1047: try {
1048: System.out
1049: .println("Try passing array with Statement.execute");
1050: s.execute("insert into t11(c11) select c21 from t21",
1051: colPositions);
1052: System.out
1053: .println("ERROR: shouldn't be able to pass array with Statement.execute");
1054:
1055: } catch (SQLException e) {
1056: if ((e.getMessage() != null && e.getMessage().indexOf(
1057: "Driver not capable") >= 0)
1058: || (e.getSQLState() != null && (e.getSQLState()
1059: .startsWith("0A"))))
1060: System.out
1061: .println("PASS - expected exception - Feature not implemented");
1062: else
1063: System.out.println("Unexpected FAILURE at " + e);
1064:
1065: }
1066: try {
1067: System.out
1068: .println("Try passing array with Statement.executeUpdate");
1069: s.executeUpdate("insert into t11(c11) select c21 from t21",
1070: colPositions);
1071: System.out
1072: .println("ERROR: shouldn't be able to pass array with Statement.executeUpdate");
1073: } catch (SQLException e) {
1074: if (e.getSQLState() == null
1075: || e.getSQLState().startsWith("0A"))
1076: dumpExpectedSQLExceptions(e);
1077: else
1078: JDBCDisplayUtil.ShowSQLException(System.out, e);
1079: }
1080:
1081: System.out
1082: .println("Test21ps - insert select with columnIndexes[] array should fail");
1083: try {
1084: System.out
1085: .println("Try passing array with Connection.prepareStatement");
1086: ps = con.prepareStatement(
1087: "insert into t11(c11) select c21 from t21",
1088: colPositions);
1089: System.out
1090: .println("ERROR: shouldn't be able to pass array with Connection.prepareStatement");
1091: } catch (SQLException e) {
1092: if (e.getSQLState() == null
1093: || e.getSQLState().startsWith("0A"))
1094: dumpExpectedSQLExceptions(e);
1095: else
1096: JDBCDisplayUtil.ShowSQLException(System.out, e);
1097: }
1098:
1099: //Test22 - insert select with columnNames[] array
1100: System.out
1101: .println("Test22 - insert select with columnNames[] array should fail");
1102: String colNames[] = new String[1];
1103: colNames[0] = "C11";
1104: try {
1105: System.out
1106: .println("Try passing array with Statement.execute");
1107: s.execute("insert into t11(c11) select c21 from t21",
1108: colNames);
1109: System.out
1110: .println("ERROR: shouldn't be able to pass array with Statement.execute");
1111: } catch (SQLException e) {
1112: if (e.getSQLState() == null
1113: || e.getSQLState().startsWith("0A"))
1114: dumpExpectedSQLExceptions(e);
1115: else
1116: JDBCDisplayUtil.ShowSQLException(System.out, e);
1117: }
1118: try {
1119: System.out
1120: .println("Try passing array with Statement.executeUpdate");
1121: s.executeUpdate("insert into t11(c11) select c21 from t21",
1122: colNames);
1123: System.out
1124: .println("ERROR: shouldn't be able to pass array with Statement.executeUpdate");
1125: } catch (SQLException e) {
1126: if (e.getSQLState() == null
1127: || e.getSQLState().startsWith("0A"))
1128: dumpExpectedSQLExceptions(e);
1129: else
1130: JDBCDisplayUtil.ShowSQLException(System.out, e);
1131: }
1132:
1133: System.out
1134: .println("Test22ps - insert select with columnNames[] array should fail");
1135: try {
1136: System.out
1137: .println("Try passing array with Connection.prepareStatement");
1138: ps = con.prepareStatement(
1139: "insert into t11(c11) select c21 from t21",
1140: colNames);
1141: System.out
1142: .println("ERROR: shouldn't be able to pass array with Connection.prepareStatement");
1143: } catch (SQLException e) {
1144: if (e.getSQLState() == null
1145: || e.getSQLState().startsWith("0A"))
1146: dumpExpectedSQLExceptions(e);
1147: else
1148: JDBCDisplayUtil.ShowSQLException(System.out, e);
1149: }
1150: con.rollback();
1151: }
1152:
1153: public static void doTest1920(Statement s, Connection con)
1154: throws SQLException {
1155: //Test19 - bug 4838 no auto generated key resultset generated for INSERT with
1156: //generated keys if server-side methods are invoked.
1157: //Adding the tests to try server side methods which toggle the auto generated flag
1158: //and make sure we don't loose the client side setting in the process
1159: System.out
1160: .println("Test19 - fix the no auto generated key resultset generated for INSERT with "
1161: + "generated keys if server-side methods are invoked");
1162: s
1163: .execute("CREATE FUNCTION MMWNI() RETURNS VARCHAR(20) LANGUAGE JAVA EXTERNAL NAME 'org.apache.derbyTesting.functionTests.tests.jdbcapi.autoGeneratedJdbc30.MyMethodWithNoInsert' PARAMETER STYLE JAVA READS SQL DATA");
1164: con.commit();
1165: s.execute("insert into t21 values(40,MMWNI())",
1166: Statement.RETURN_GENERATED_KEYS);
1167: System.out
1168: .println("Back to client side looking for auto generated keys");
1169: dumpRS(s.getGeneratedKeys());
1170:
1171: //Verify data in the table
1172: dumpRS(s.executeQuery("select count(*) from t21"));
1173: s.execute("delete from t11");
1174:
1175: s.execute("DROP FUNCTION MMWNI");
1176: con.commit();
1177: s.close();
1178:
1179: // Test 20 - BUG 4837 garbage collection of the generated key result sets was closing the activation.
1180: System.out
1181: .println("Test20 - bug 4837garbage collection of the generated key result sets was closing the activation.");
1182: PreparedStatement ps = con.prepareStatement(
1183: "insert into t11(c11) values(?)",
1184: Statement.RETURN_GENERATED_KEYS);
1185:
1186: for (int i = 0; i < 100; i++) {
1187: ps.setInt(1, 100 + i);
1188: ps.executeUpdate();
1189:
1190: ResultSet rs = ps.getGeneratedKeys();
1191: while (rs.next()) {
1192: rs.getInt(1);
1193: }
1194: rs.close();
1195: con.commit();
1196:
1197: System.runFinalization();
1198: System.gc();
1199: System.runFinalization();
1200: System.gc();
1201: }
1202: }
1203: }
|