KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > functionTests > tests > lang > scrollCursors2


1 /*
2
3    Derby - Class org.apache.derbyTesting.functionTests.tests.lang.scrollCursors2
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derbyTesting.functionTests.tests.lang;
23
24 import java.io.IOException JavaDoc;
25
26 import java.sql.CallableStatement JavaDoc;
27 import java.sql.Connection JavaDoc;
28 import java.sql.DriverManager JavaDoc;
29 import java.sql.Statement JavaDoc;
30 import java.sql.PreparedStatement JavaDoc;
31 import java.sql.ResultSet JavaDoc;
32 import java.sql.ResultSetMetaData JavaDoc;
33 import java.sql.SQLException JavaDoc;
34 import java.sql.SQLWarning JavaDoc;
35 import java.sql.Types JavaDoc;
36 import java.sql.Date JavaDoc;
37 import java.sql.Time JavaDoc;
38 import java.sql.Timestamp JavaDoc;
39
40 import org.apache.derby.tools.ij;
41 import org.apache.derby.tools.JDBCDisplayUtil;
42 import org.apache.derbyTesting.functionTests.util.TestUtil;
43
44 /**
45  * Test of scroll cursors.
46  *
47  * @author Jerry Brenner
48  */

49
50 public class scrollCursors2 {
51
52         private static boolean isDerbyNetClient = false;
53     
54     public static void main(String JavaDoc[] args) {
55         boolean passed = true;
56         Connection JavaDoc conn = null;
57         Statement JavaDoc s_i_r = null;
58
59         /* Run all parts of this test, and catch any exceptions */
60         try {
61             System.out.println("Test scrollCurors2 starting");
62
63                         isDerbyNetClient = TestUtil.isDerbyNetClientFramework();
64             // use the ij utility to read the property file and
65
// make the initial connection.
66
ij.getPropertyArg(args);
67             conn = ij.startJBMS();
68             cleanUp(conn);
69             conn.setAutoCommit(false);
70
71             /* Create the table and do any other set-up */
72             passed = passed && setUpTest(conn);
73
74             // Negative tests with forward only cursors.
75
passed = passed && forwardOnlyNegative(conn);
76
77             // Positive tests with forward only cursors.
78
passed = passed && forwardOnlyPositive(conn);
79
80             // Tests with scroll sensitive cursors
81
passed = passed && scrollSensitiveTest(conn);
82
83             // Positive tests for scroll insensitive cursors
84
passed = passed && scrollInsensitivePositive(conn);
85
86             // Negative tests for scroll insensitive cursors
87
passed = passed && scrollInsensitiveNegative(conn);
88
89             // "test" scrolling and CallableStatements
90
passed = passed && testCallableStatements(conn);
91
92             // tests for PreparedStatement.getMetaData()
93
passed = passed && getMetaDataTests(conn);
94                         
95                         // test scrollable with different maxRows and fetchSize
96
passed = passed && scrollVerifyMaxRowWithFetchSize(conn, 10, 10);
97                         passed = passed && scrollVerifyMaxRowWithFetchSize(conn, 10, 5);
98                         passed = passed && scrollVerifyMaxRowWithFetchSize(conn, 10, 0);
99                         passed = passed && scrollVerifyMaxRowWithFetchSize(conn, 0, 0);
100                         passed = passed && scrollVerifyMaxRowWithFetchSize(conn, 0, 5);
101                         passed = passed && scrollVerifyMaxRowWithFetchSize(conn, 0, 10);
102                         passed = passed && scrollVerifyMaxRowWithFetchSize(conn, 0, 15);
103                         
104         }
105         catch (SQLException JavaDoc se)
106         {
107             passed = false;
108             dumpSQLExceptions(se);
109         }
110         catch (Throwable JavaDoc e)
111         {
112             System.out.println("FAIL -- unexpected exception caught in main():\n");
113             System.out.println(e.getMessage());
114             e.printStackTrace();
115             passed = false;
116         }
117         finally
118         {
119
120             /* Test is finished - clean up after ourselves */
121             passed = passed && cleanUp(conn, s_i_r);
122         }
123
124         if (passed)
125             System.out.println("PASS");
126
127         System.out.println("Test scrollCursors2 finished");
128     }
129
130     static private void dumpSQLExceptions (SQLException JavaDoc se) {
131         System.out.println("FAIL -- unexpected exception");
132         while (se != null) {
133             System.out.print("SQLSTATE("+se.getSQLState()+"):");
134             se.printStackTrace();
135             se = se.getNextException();
136         }
137     }
138
139     /**
140      * Set up the test.
141      *
142      * This method creates the table used by the rest of the test.
143      *
144      * @param conn The Connection
145      *
146      * @return true if it succeeds, false if it doesn't
147      *
148      * @exception SQLException Thrown if some unexpected error happens
149      */

150
151     static boolean setUpTest(Connection JavaDoc conn)
152                     throws SQLException JavaDoc
153     {
154         boolean passed = true;
155         int rows;
156         PreparedStatement JavaDoc ps;
157         Statement JavaDoc s_i_r;
158
159         s_i_r = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
160                                      ResultSet.CONCUR_READ_ONLY);
161
162         /* Create a table */
163         s_i_r.execute("create table t (i int, c50 char(50))");
164
165         /* Populate the table */
166         s_i_r.execute("insert into t (i) values (2), (3), (4), (5), (6)");
167         s_i_r.execute("update t set c50 = RTRIM(CAST (i AS CHAR(50)))");
168         s_i_r.close();
169
170         return passed;
171     }
172
173     /**
174      * Negative tests for forward only cursors.
175      *
176      * This method tests forward only cursors.
177      *
178      * @param conn The Connection
179      *
180      * @return true if it succeeds, false if it doesn't
181      *
182      * @exception SQLException Thrown if some unexpected error happens
183      */

184
185     static boolean forwardOnlyNegative( Connection JavaDoc conn)
186         throws SQLException JavaDoc
187     {
188         boolean passed = true;
189         PreparedStatement JavaDoc ps_f_r = null;
190         ResultSet JavaDoc rs;
191         SQLWarning JavaDoc warning;
192         Statement JavaDoc s_f_r = null;
193
194         s_f_r = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
195                                      ResultSet.CONCUR_READ_ONLY);
196         // We should have gotten no warnings and a read only forward only cursor
197
warning = conn.getWarnings();
198         while (warning != null)
199         {
200             System.out.println("warning = " + warning);
201             warning = warning.getNextWarning();
202         }
203         conn.clearWarnings();
204
205         // Verify that setMaxRows(-1) fails
206
try
207         {
208             s_f_r.setMaxRows(-1);
209             // Should never get here
210
System.out.println("setMaxRows(-1) expected to fail");
211             passed = false;
212         }
213         catch (SQLException JavaDoc sqle)
214         {
215             /* Check to be sure the exception is the one we expect */
216                         if (!isDerbyNetClient) {
217                             passed = passed && checkException(sqle, "XJ063");
218                         } else {
219                             System.out.println(sqle.getMessage());
220                         }
221         }
222         // Verify maxRows still 0
223
if (s_f_r.getMaxRows() != 0)
224         {
225             System.out.println("getMaxRows() expected to return 0");
226             passed = false;
227         }
228
229         // Verify that result set from statement is
230
// scroll insensitive and read only
231
rs = s_f_r.executeQuery("select * from t");
232         if (rs.getType() != ResultSet.TYPE_FORWARD_ONLY)
233         {
234             System.out.println("cursor type = " + rs.getType() +
235                                ", not " + ResultSet.TYPE_FORWARD_ONLY);
236         }
237         if (rs.getConcurrency() != ResultSet.CONCUR_READ_ONLY)
238         {
239             System.out.println("concurrency = " + rs.getConcurrency() +
240                                ", not " + ResultSet.CONCUR_READ_ONLY);
241         }
242
243         // Verify that first(), etc. don't work
244
try
245         {
246             rs.first();
247             // Should never get here
248
System.out.println("first() expected to fail");
249             passed = false;
250         }
251         catch (SQLException JavaDoc sqle)
252         {
253             /* Check to be sure the exception is the one we expect */
254                         if (!isDerbyNetClient) {
255                             passed = passed && checkException(sqle, "XJ061");
256                         } else {
257                             System.out.println(sqle.getMessage());
258                         }
259
260         }
261         try
262         {
263             rs.beforeFirst();
264             // Should never get here
265
System.out.println("beforeFirst() expected to fail");
266             passed = false;
267         }
268         catch (SQLException JavaDoc sqle)
269         {
270             /* Check to be sure the exception is the one we expect */
271                         if (!isDerbyNetClient) {
272                             passed = passed && checkException(sqle, "XJ061");
273                         } else {
274                             System.out.println(sqle.getMessage());
275                         }
276
277         }
278         try
279         {
280             rs.isBeforeFirst();
281             // Should never get here
282
System.out.println("isBeforeFirst() expected to fail");
283             passed = false;
284         }
285         catch (SQLException JavaDoc sqle)
286         {
287             /* Check to be sure the exception is the one we expect */
288                         if (!isDerbyNetClient) {
289                             passed = passed && checkException(sqle, "XJ061");
290                         } else {
291                             System.out.println(sqle.getMessage());
292                         }
293
294         }
295         try
296         {
297             rs.isAfterLast();
298             // Should never get here
299
System.out.println("isAfterLast() expected to fail");
300             passed = false;
301         }
302         catch (SQLException JavaDoc sqle)
303         {
304             /* Check to be sure the exception is the one we expect */
305                         if (!isDerbyNetClient) {
306                             passed = passed && checkException(sqle, "XJ061");
307                         } else {
308                             System.out.println(sqle.getMessage());
309                         }
310
311         }
312         try
313         {
314             rs.isFirst();
315             // Should never get here
316
System.out.println("isFirst() expected to fail");
317             passed = false;
318         }
319         catch (SQLException JavaDoc sqle)
320         {
321             /* Check to be sure the exception is the one we expect */
322                         if (!isDerbyNetClient) {
323                             passed = passed && checkException(sqle, "XJ061");
324                         } else {
325                             System.out.println(sqle.getMessage());
326                         }
327         }
328         try
329         {
330             rs.isLast();
331             // Should never get here
332
System.out.println("isLast() expected to fail");
333             passed = false;
334         }
335         catch (SQLException JavaDoc sqle)
336         {
337             /* Check to be sure the exception is the one we expect */
338                         if (!isDerbyNetClient) {
339                             passed = passed && checkException(sqle, "XJ061");
340                         } else {
341                             System.out.println(sqle.getMessage());
342                         }
343         }
344         try
345         {
346             rs.absolute(1);
347             // Should never get here
348
System.out.println("absolute() expected to fail");
349             passed = false;
350         }
351         catch (SQLException JavaDoc sqle)
352         {
353             /* Check to be sure the exception is the one we expect */
354                         if (!isDerbyNetClient) {
355                             passed = passed && checkException(sqle, "XJ061");
356                         } else {
357                             System.out.println(sqle.getMessage());
358                         }
359         }
360         try
361         {
362             rs.relative(1);
363             // Should never get here
364
System.out.println("relative() expected to fail");
365             passed = false;
366         }
367         catch (SQLException JavaDoc sqle)
368         {
369             /* Check to be sure the exception is the one we expect */
370                         if (!isDerbyNetClient) {
371                             passed = passed && checkException(sqle, "XJ061");
372                         } else {
373                             System.out.println(sqle.getMessage());
374                         }
375         }
376
377         // setFetchDirection should fail
378
try
379         {
380             rs.setFetchDirection(ResultSet.FETCH_FORWARD);
381             // Should never get here
382
System.out.println("setFetchDirection() expected to fail");
383             passed = false;
384         }
385         catch (SQLException JavaDoc sqle)
386         {
387             /* Check to be sure the exception is the one we expect */
388                         if (!isDerbyNetClient) {
389                             passed = passed && checkException(sqle, "XJ061");
390                         } else {
391                             System.out.println(sqle.getMessage());
392                         }
393         }
394
395         /* Book says that getFetchDirection(), getFetchSize() and
396          * setFetchSize() are all okay.
397          */

398         if ((rs.getFetchSize() != 1 && !isDerbyNetClient) || (rs.getFetchSize() != 0 && isDerbyNetClient))
399         {
400                         if (!isDerbyNetClient) {
401                             System.out.println("getFetchSize() expected to return 1");
402                         } else {
403                             System.out.println("getFetchSize() expected to return 0");
404                         }
405                         passed = false;
406         }
407         rs.setFetchSize(5);
408         if (rs.getFetchSize() != 5)
409         {
410             System.out.println("getFetchSize() expected to return 5");
411             passed = false;
412         }
413
414         if (rs.getFetchDirection() != ResultSet.FETCH_FORWARD)
415         {
416             System.out.println(
417                 "getFetchDirection() expected to return FETCH_FORWARD, not " +
418                 rs.getFetchDirection());
419             passed = false;
420         }
421
422         rs.close();
423         s_f_r.close();
424
425         ps_f_r = conn.prepareStatement(
426                                      "select * from t",
427                                      ResultSet.TYPE_FORWARD_ONLY,
428                                      ResultSet.CONCUR_READ_ONLY);
429         // We should have gotten no warnings and a read only forward only cursor
430
warning = conn.getWarnings();
431         while (warning != null)
432         {
433             System.out.println("warning = " + warning);
434             warning = warning.getNextWarning();
435         }
436         conn.clearWarnings();
437
438         // Verify that result set from statement is
439
// scroll insensitive and read only
440
rs = ps_f_r.executeQuery();
441         if (rs.getType() != ResultSet.TYPE_FORWARD_ONLY)
442         {
443             System.out.println("cursor type = " + rs.getType() +
444                                ", not " + ResultSet.TYPE_FORWARD_ONLY);
445         }
446         if (rs.getConcurrency() != ResultSet.CONCUR_READ_ONLY)
447         {
448             System.out.println("concurrency = " + rs.getConcurrency() +
449                                ", not " + ResultSet.CONCUR_READ_ONLY);
450         }
451
452         // Verify that first() doesn't work
453
try
454         {
455             rs.first();
456             // Should never get here
457
System.out.println("first() expected to fail");
458             passed = false;
459         }
460         catch (SQLException JavaDoc sqle)
461         {
462             /* Check to be sure the exception is the one we expect */
463                         if (!isDerbyNetClient) {
464                             passed = passed && checkException(sqle, "XJ061");
465                         } else {
466                             System.out.println(sqle.getMessage());
467                         }
468
469         }
470         rs.close();
471         ps_f_r.close();
472
473         return passed;
474     }
475
476     /**
477      * Positive tests for forward only cursors.
478      *
479      * This method tests forward only cursors.
480      *
481      * @param conn The Connection
482      *
483      * @return true if it succeeds, false if it doesn't
484      *
485      * @exception SQLException Thrown if some unexpected error happens
486      */

487
488     static boolean forwardOnlyPositive( Connection JavaDoc conn)
489         throws SQLException JavaDoc
490     {
491         boolean passed = true;
492         ResultSet JavaDoc rs;
493         SQLWarning JavaDoc warning;
494         Statement JavaDoc s_f_r = null;
495
496         s_f_r = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
497                                      ResultSet.CONCUR_READ_ONLY);
498         // We should have gotten no warnings and a read only forward only cursor
499
warning = conn.getWarnings();
500         while (warning != null)
501         {
502             System.out.println("warning = " + warning);
503             warning = warning.getNextWarning();
504         }
505         conn.clearWarnings();
506
507         // Verify that setMaxRows(4) succeeds
508
s_f_r.setMaxRows(5);
509         if (s_f_r.getMaxRows() != 5)
510         {
511             System.out.println("getMaxRows() expected to return 5");
512             passed = false;
513         }
514         rs = s_f_r.executeQuery("values 1, 2, 3, 4, 5, 6");
515         if (rs == null)
516         {
517             System.out.println("rs expected to be non-null.");
518             passed = false;
519         }
520         // Iterate straight thru RS, expect only 5 rows.
521
for (int index = 1; index < 6; index++)
522         {
523             if (! rs.next())
524             {
525                 System.out.println("rs.next() failed, index = " + index);
526                 passed = false;
527                 break;
528             }
529         }
530         // We should not see another row (only 5, not 6)
531
if (rs.next())
532         {
533             System.out.println("rs.next() failed, should not have seen 6th row.");
534             passed = false;
535         }
536         rs.close();
537         s_f_r.close();
538         return passed;
539     }
540
541     /**
542      * Scroll sensitive cursor tests
543      *
544      * This method tests scroll sensitive cursors.
545      * (Not implemented, so we should get back
546      * scroll insensitive curors with read only concurrency.)
547      *
548      * @param conn The Connection
549      *
550      * @return true if it succeeds, false if it doesn't
551      *
552      * @exception SQLException Thrown if some unexpected error happens
553      */

554
555     static boolean scrollSensitiveTest( Connection JavaDoc conn)
556         throws SQLException JavaDoc
557     {
558         ResultSet JavaDoc rs;
559         SQLWarning JavaDoc warning;
560         Statement JavaDoc s_s_r = null; // sensitive, read only
561
Statement JavaDoc s_s_u = null; // sensitive, updatable
562

563
564         s_s_r = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
565                                      ResultSet.CONCUR_READ_ONLY);
566
567         // We should have gotten a warning and a scroll insensitive cursor
568
warning = conn.getWarnings();
569         while (warning != null)
570         {
571             System.out.println("warning = " + warning);
572             warning = warning.getNextWarning();
573         }
574         conn.clearWarnings();
575
576         // Verify that result set from statement is
577
// scroll insensitive and read only
578
rs = s_s_r.executeQuery("select * from t");
579         if (rs.getType() != ResultSet.TYPE_SCROLL_INSENSITIVE)
580         {
581             System.out.println("cursor type = " + rs.getType() +
582                                ", not " + ResultSet.TYPE_SCROLL_INSENSITIVE);
583         }
584         if (rs.getConcurrency() != ResultSet.CONCUR_READ_ONLY)
585         {
586             System.out.println("concurrency = " + rs.getConcurrency() +
587                                ", not " + ResultSet.CONCUR_READ_ONLY);
588         }
589         rs.close();
590
591         // Close the statement
592
s_s_r.close();
593
594         s_s_u = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
595                                      ResultSet.CONCUR_UPDATABLE);
596         // We should have gotten 1 warning and a updatable scroll
597
// insensitive cursor.
598
warning = conn.getWarnings();
599         while (warning != null)
600         {
601             System.out.println("warning = " + warning);
602             warning = warning.getNextWarning();
603         }
604         conn.clearWarnings();
605
606         // Verify that result set from statement is
607
// scroll insensitive and read only
608
rs = s_s_u.executeQuery("select * from t");
609         if (rs.getType() != ResultSet.TYPE_SCROLL_INSENSITIVE)
610         {
611             System.out.println("cursor type = " + rs.getType() +
612                                ", not " + ResultSet.TYPE_SCROLL_INSENSITIVE);
613         }
614         if (rs.getConcurrency() != ResultSet.CONCUR_UPDATABLE)
615         {
616             System.out.println("concurrency = " + rs.getConcurrency() +
617                                ", not " + ResultSet.CONCUR_UPDATABLE);
618         }
619         rs.close();
620
621
622         return true;
623     }
624
625     /**
626      * Positive tests for scroll insensitive cursor.
627      *
628      * @param conn The connection to use.
629      *
630      * @return Whether or not we were successful.
631      *
632      * @exception SQLException Thrown if some unexpected error happens
633      */

634     static boolean scrollInsensitivePositive( Connection JavaDoc conn)
635         throws SQLException JavaDoc
636     {
637         boolean passed = true;
638         PreparedStatement JavaDoc ps_i_r = null;
639         ResultSet JavaDoc rs;
640         SQLWarning JavaDoc warning;
641         Statement JavaDoc s_i_r = null; // insensitive, read only
642

643
644         s_i_r = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
645                                      ResultSet.CONCUR_READ_ONLY);
646
647         // We should not have gotten any warnings
648
// and should have gotten a scroll insensitive cursor
649
warning = conn.getWarnings();
650         while (warning != null)
651         {
652             System.out.println("unexpected warning = " + warning);
653             warning = warning.getNextWarning();
654             passed = false;
655         }
656         conn.clearWarnings();
657
658         // run a query
659
rs = s_i_r.executeQuery("select * from t");
660         // verify scroll insensitive and read only
661
if (rs.getType() != ResultSet.TYPE_SCROLL_INSENSITIVE)
662         {
663             System.out.println(
664                 "rs.getType() expected to return TYPE_SCROLL_INSENSITIVE, not " +
665                 rs.getType());
666             passed = false;
667         }
668         if (rs.getConcurrency() != ResultSet.CONCUR_READ_ONLY)
669         {
670             System.out.println(
671                 "rs.getConcurrency() expected to return CONCUR_READ_ONLY, not " +
672                 rs.getConcurrency());
673             passed = false;
674         }
675         
676         // We should be positioned before the 1st row
677
if (! rs.isBeforeFirst())
678         {
679             System.out.println("expected to be before the 1st row");
680             passed = false;
681         }
682                 if (rs.absolute(0))
683                 {
684             System.out.println("absolute(0) expected to return false");
685             passed = false;
686                 }
687         if (! rs.isBeforeFirst())
688         {
689             System.out.println("still expected to be before the 1st row");
690             passed = false;
691         }
692         // go to first row
693
if (! rs.first())
694         {
695             System.out.println("expected first() to succeed");
696             passed = false;
697         }
698         if (rs.getInt(1) != 2)
699         {
700             System.out.println(
701                 "rs.getInt(1) expected to return 2, not " + rs.getInt(1));
702             passed = false;
703         }
704         if (! rs.isFirst())
705         {
706             System.out.println("expected to be on the 1st row");
707             passed = false;
708         }
709         // move to before first
710
rs.beforeFirst();
711         if (! rs.isBeforeFirst())
712         {
713             System.out.println("expected to be before the 1st row");
714             passed = false;
715         }
716         // move to last row
717
if (! rs.last())
718         {
719             System.out.println("expected last() to succeed");
720             passed = false;
721         }
722         if (! rs.isLast())
723         {
724             System.out.println("expected to be on the last row");
725             passed = false;
726         }
727         if (rs.isAfterLast())
728         {
729             System.out.println("not expected to be after the last row");
730             passed = false;
731         }
732         if (rs.getInt(1) != 6)
733         {
734             System.out.println(
735                 "rs.getInt(1) expected to return 6, not " + rs.getInt(1));
736             passed = false;
737         }
738         if (rs.next())
739         {
740             System.out.println("not expected to find another row");
741             passed = false;
742         }
743         if (! rs.isAfterLast())
744         {
745             System.out.println("expected to be after the last row");
746             passed = false;
747         }
748
749         // We're after the last row, verify that only isAfterLast()
750
// returns true
751
if (rs.isLast())
752         {
753             System.out.println("not expected to be on the last row");
754             passed = false;
755         }
756         if (rs.isFirst())
757         {
758             System.out.println("not expected to be on the first row");
759             passed = false;
760         }
761         if (rs.isBeforeFirst())
762         {
763             System.out.println("not expected to be before the first row");
764             passed = false;
765         }
766
767         // get/setFetchDirection()
768
if (rs.getFetchDirection() != ResultSet.FETCH_FORWARD)
769         {
770             System.out.println(
771                 "getFetchDirection() expected to return FETCH_FORWARD, not " +
772                 rs.getFetchDirection());
773             passed = false;
774         }
775         rs.setFetchDirection(ResultSet.FETCH_UNKNOWN);
776         if (rs.getFetchDirection() != ResultSet.FETCH_UNKNOWN)
777         {
778             System.out.println(
779                 "getFetchDirection() expected to return FETCH_UNKNOWN, not " +
780                 rs.getFetchDirection());
781             passed = false;
782         }
783
784         // get/setFetchSize()
785
if (
786                         (rs.getFetchSize() != 1 && !isDerbyNetClient) ||
787                         (rs.getFetchSize() != 64 && isDerbyNetClient))
788         {
789                         if (!isDerbyNetClient) {
790                             System.out.println(
791                                     "getFetchSize() expected to return 1, not " + rs.getFetchSize());
792                         } else {
793                             System.out.println(
794                                     "getFetchSize() expected to return 64, not " + rs.getFetchSize());
795                         }
796             passed = false;
797         }
798         rs.setFetchSize(5);
799         if (rs.getFetchSize() != 5)
800         {
801             System.out.println(
802                 "getFetchSize() expected to return 5, not " + rs.getFetchSize());
803             passed = false;
804         }
805         // setFetchSize() to 0 should have no effect.
806
// for client server, fetchSize should have to 64
807
rs.setFetchSize(0);
808         if (
809                         (rs.getFetchSize() != 5 && !isDerbyNetClient) ||
810                         (rs.getFetchSize() != 64 && isDerbyNetClient))
811         {
812                         if (!isDerbyNetClient) {
813                             System.out.println(
814                 "getFetchSize() expected to return 5, not " + rs.getFetchSize());
815                         } else {
816                             System.out.println(
817                 "getFetchSize() expected to return 64, not " + rs.getFetchSize());
818                         }
819
820             passed = false;
821         }
822         // done
823
rs.close();
824
825
826         // Empty result set tests (DERBY-992)
827
rs = s_i_r.executeQuery("select * from t where 1=0");
828         rs.afterLast();
829         if (rs.isAfterLast()) {
830             System.out.println("afterLast() on empty RS should be no-op");
831         }
832         
833         rs.beforeFirst();
834         if (rs.isBeforeFirst()) {
835             System.out.println("beforeFirst() on empty RS should be no-op");
836         }
837
838         rs.close();
839
840         ps_i_r = conn.prepareStatement(
841                                      "select * from t",
842                                      ResultSet.TYPE_SCROLL_INSENSITIVE,
843                                      ResultSet.CONCUR_READ_ONLY);
844
845         // We should not have gotten any warnings
846
// and should have gotten a prepared scroll insensitive cursor
847
warning = conn.getWarnings();
848         while (warning != null)
849         {
850             System.out.println("unexpected warning = " + warning);
851             warning = warning.getNextWarning();
852             passed = false;
853         }
854         conn.clearWarnings();
855
856         rs = ps_i_r.executeQuery();
857         // make sure it's scrollable
858
rs.last();
859         rs.close();
860         ps_i_r.close();
861
862         // Check setMaxRows()/getMaxRows()
863
if (s_i_r.getMaxRows() != 0)
864         {
865             System.out.println("getMaxRows() expected to return 0");
866             passed = false;
867         }
868         s_i_r.setMaxRows(5);
869         if (s_i_r.getMaxRows() != 5)
870         {
871             System.out.println("getMaxRows() expected to return 5");
872             passed = false;
873         }
874         rs = s_i_r.executeQuery("values 1, 2, 3, 4, 5, 6");
875         if (rs == null)
876         {
877             System.out.println("rs expected to be non-null.");
878             passed = false;
879         }
880         // Iterate straight thru RS, expect only 5 rows.
881
for (int index = 1; index < 6; index++)
882         {
883             if (! rs.next())
884             {
885                 System.out.println("rs.next() failed, index = " + index);
886                 passed = false;
887                 break;
888             }
889         }
890         // We should not see another row (only 5, not 6)
891
if (rs.next())
892         {
893             System.out.println("rs.next() failed, should not have seen 6th row.");
894             passed = false;
895         }
896         rs.close();
897         // Jump around and verify setMaxRows() works.
898
rs = s_i_r.executeQuery("values 1, 2, 3, 4, 5, 6");
899         if (rs == null)
900         {
901             System.out.println("rs expected to be non-null.");
902             passed = false;
903         }
904         if (!rs.last())
905         {
906             System.out.println("rs.last() failed.");
907             passed = false;
908         }
909         // Iterate backwards thru RS, expect only 4 more (5 total) rows.
910
for (int index = 1; index < 5; index++)
911         {
912             if (! rs.previous())
913             {
914                 System.out.println("rs.previous() failed, index = " + index);
915                 passed = false;
916                 break;
917             }
918         }
919         // We should not see another row (only 5, not 6)
920
if (rs.previous())
921         {
922             System.out.println("rs.previous() failed, should not have seen 6th row.");
923             passed = false;
924         }
925         rs.close();
926         rs = s_i_r.executeQuery("values 1, 2, 3, 4, 5, 6");
927         if (rs == null)
928         {
929             System.out.println("rs expected to be non-null.");
930             passed = false;
931         }
932         rs.afterLast();
933         // Iterate backwards thru RS, expect only 5 rows.
934
for (int index = 1; index < 6; index++)
935         {
936             if (! rs.previous())
937             {
938                 System.out.println("rs.previous() failed, index = " + index);
939                 passed = false;
940                 break;
941             }
942         }
943         // We should not see another row (only 5, not 6)
944
if (rs.previous())
945         {
946             System.out.println("rs.previous() failed, should not have seen 6th row.");
947             passed = false;
948         }
949         rs.close();
950         // Verify setting maxRows back to 0 works.
951
s_i_r.setMaxRows(0);
952         rs = s_i_r.executeQuery("values 1, 2, 3, 4, 5, 6");
953         if (rs == null)
954         {
955             System.out.println("rs expected to be non-null.");
956             passed = false;
957         }
958         // Iterate straight thru RS, expect 6 rows.
959
for (int index = 1; index < 7; index++)
960         {
961             if (! rs.next())
962             {
963                 System.out.println("rs.next() failed, index = " + index);
964                 passed = false;
965                 break;
966             }
967         }
968         // We should not see another row
969
if (rs.next())
970         {
971             System.out.println("rs.next() failed, should not have seen another row.");
972             passed = false;
973         }
974         rs.close();
975
976         return passed;
977     }
978
979     /**
980      * Negative tests for scroll insensitive cursor.
981      *
982      * @param conn The connection to use.
983      *
984      * @return Whether or not we were successful.
985      *
986      * @exception SQLException Thrown if some unexpected error happens
987      */

988     static boolean scrollInsensitiveNegative( Connection JavaDoc conn)
989         throws SQLException JavaDoc
990     {
991         boolean passed = true;
992         ResultSet JavaDoc rs;
993         SQLWarning JavaDoc warning;
994         Statement JavaDoc s_i_r = null; // insensitive, read only
995

996         s_i_r = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
997                                      ResultSet.CONCUR_READ_ONLY);
998
999         // We should not have gotten any warnings
1000
// and should have gotten a scroll insensitive cursor
1001
warning = conn.getWarnings();
1002        while (warning != null)
1003        {
1004            System.out.println("unexpected warning = " + warning);
1005            warning = warning.getNextWarning();
1006            passed = false;
1007        }
1008        conn.clearWarnings();
1009
1010        // Verify that setMaxRows(-1) fails
1011
try
1012        {
1013            s_i_r.setMaxRows(-1);
1014            // Should never get here
1015
System.out.println("setMaxRows(-1) expected to fail");
1016            passed = false;
1017        }
1018        catch (SQLException JavaDoc sqle)
1019        {
1020            /* Check to be sure the exception is the one we expect */
1021                        if (!isDerbyNetClient) {
1022                            passed = passed && checkException(sqle, "XJ063");
1023                        } else {
1024                            System.out.println(sqle.getMessage());
1025                        }
1026
1027        }
1028        // Verify maxRows still 0
1029
if (s_i_r.getMaxRows() != 0)
1030        {
1031            System.out.println("getMaxRows() expected to return 0");
1032            passed = false;
1033        }
1034
1035        // Empty result set
1036
rs = s_i_r.executeQuery("select * from t where 1=0");
1037        // isBeforeFirst() and isAfterLast() should always return false
1038
// when result set is empty
1039
if (rs.isBeforeFirst())
1040        {
1041            System.out.println("isBeforeFirst() expected to return false on empty result set");
1042            passed = false;
1043        }
1044        if (rs.next())
1045        {
1046            System.out.println("rs.next() expected to show result set is empty");
1047            passed = false;
1048        }
1049        if (rs.previous())
1050        {
1051            System.out.println("rs.previous() expected to show result set is empty");
1052            passed = false;
1053        }
1054        if (rs.isAfterLast())
1055        {
1056            System.out.println("isAfterLast() expected to return false on empty result set");
1057            passed = false;
1058        }
1059        if (rs.isFirst())
1060        {
1061            System.out.println("isFirst() expected to return false on empty result set");
1062            passed = false;
1063        }
1064        if (rs.isLast())
1065        {
1066            System.out.println("isLast() expected to return false on empty result set");
1067            passed = false;
1068        }
1069
1070        if (rs.relative(0))
1071        {
1072            System.out.println("relative(0) expected to return false on empty result set");
1073            passed = false;
1074        }
1075
1076        if (rs.relative(1))
1077        {
1078            System.out.println("relative(1) expected to return false on empty result set");
1079            passed = false;
1080        }
1081
1082        if (rs.relative(-1))
1083        {
1084            System.out.println("relative(-1) expected to return false on empty result set");
1085            passed = false;
1086        }
1087
1088        if (rs.absolute(0))
1089        {
1090            System.out.println("absolute(0) expected to return false on empty result set");
1091            passed = false;
1092        }
1093        if (rs.absolute(1))
1094        {
1095            System.out.println("absolute(1) expected to return false on empty result set");
1096            passed = false;
1097        }
1098
1099        if (rs.absolute(-1))
1100        {
1101            System.out.println("absolute(-1) expected to return false on empty result set");
1102            passed = false;
1103        }
1104
1105
1106        rs.close();
1107        // End of empty result set tests
1108

1109        // Non-empty result set
1110
rs = s_i_r.executeQuery("select * from t");
1111        // Negative fetch size
1112
try
1113        {
1114            rs.setFetchSize(-5);
1115            System.out.println("setFetchSize(-5) expected to fail");
1116            passed = false;
1117        }
1118        catch (SQLException JavaDoc sqle)
1119        {
1120            /* Check to be sure the exception is the one we expect */
1121                        if (!isDerbyNetClient) {
1122                            passed = passed && checkException(sqle, "XJ062");
1123                        } else {
1124                            System.out.println(sqle.getMessage());
1125                        }
1126
1127        }
1128
1129        s_i_r.close();
1130
1131        return passed;
1132    }
1133
1134
1135    /**
1136     * CallableStatement tests.
1137     *
1138     * @param conn The Connection
1139     *
1140     * @return true if it succeeds, false if it doesn't
1141     *
1142     * @exception SQLException Thrown if some unexpected error happens
1143     */

1144
1145    public static boolean testCallableStatements( Connection JavaDoc conn)
1146        throws SQLException JavaDoc
1147    {
1148        boolean passed = true;
1149        int warningCount = 0;
1150        SQLWarning JavaDoc warning;
1151        CallableStatement JavaDoc cs_s_r = null; // sensitive, read only
1152
CallableStatement JavaDoc cs_s_u = null; // sensitive, updatable
1153
CallableStatement JavaDoc cs_i_r = null; // insensitive, read only
1154
CallableStatement JavaDoc cs_f_r = null; // forward only, read only
1155

1156        cs_s_r = conn.prepareCall(
1157                                "values cast (? as Integer)",
1158                                ResultSet.TYPE_SCROLL_SENSITIVE,
1159                                ResultSet.CONCUR_READ_ONLY);
1160
1161        // We should have gotten 1 warnings
1162
warning = conn.getWarnings();
1163        while (warning != null)
1164        {
1165            System.out.println("warning = " + warning);
1166            warning = warning.getNextWarning();
1167            warningCount++;
1168        }
1169        if (warningCount != 1)
1170        {
1171            System.out.println("warningCount expected to be 1, not " +
1172                    warningCount);
1173            passed = false;
1174        }
1175        conn.clearWarnings();
1176        cs_s_r.close();
1177
1178        cs_s_u = conn.prepareCall(
1179                                "values cast (? as Integer)",
1180                                ResultSet.TYPE_SCROLL_SENSITIVE,
1181                                ResultSet.CONCUR_UPDATABLE);
1182
1183        // We should have gotten 2 warnings
1184
warningCount = 0;
1185        warning = conn.getWarnings();
1186        while (warning != null)
1187        {
1188            System.out.println("warning = " + warning);
1189            warning = warning.getNextWarning();
1190            warningCount++;
1191        }
1192        // SCROLL_INSENSITIVE and UPDATABLE implemented
1193
if (warningCount != 1)
1194        {
1195            System.out.println("warningCount expected to be 1, not " + warningCount);
1196            passed = false;
1197        }
1198        conn.clearWarnings();
1199        cs_s_u.close();
1200
1201        cs_i_r = conn.prepareCall(
1202                                "values cast (? as Integer)",
1203                                ResultSet.TYPE_SCROLL_INSENSITIVE,
1204                                ResultSet.CONCUR_READ_ONLY);
1205
1206        // We should have gotten 0 warnings
1207
warningCount = 0;
1208        warning = conn.getWarnings();
1209        while (warning != null)
1210        {
1211            System.out.println("warning = " + warning);
1212            warning = warning.getNextWarning();
1213            warningCount++;
1214        }
1215        if (warningCount != 0)
1216        {
1217            System.out.println("warningCount expected to be 0, not " +
1218                    warningCount);
1219            passed = false;
1220        }
1221        conn.clearWarnings();
1222        cs_i_r.close();
1223
1224        cs_f_r = conn.prepareCall(
1225                                "values cast (? as Integer)",
1226                                ResultSet.TYPE_FORWARD_ONLY,
1227                                ResultSet.CONCUR_READ_ONLY);
1228
1229        // We should have gotten 0 warnings
1230
warningCount = 0;
1231        warning = conn.getWarnings();
1232        while (warning != null)
1233        {
1234            System.out.println("warning = " + warning);
1235            warning = warning.getNextWarning();
1236            warningCount++;
1237        }
1238        if (warningCount != 0)
1239        {
1240            System.out.println("warningCount expected to be 0, not " + warningCount);
1241            passed = false;
1242        }
1243        conn.clearWarnings();
1244        cs_f_r.close();
1245
1246        return passed;
1247    }
1248
1249
1250    /**
1251     * Tests for PreparedStatement.getMetaData().
1252     *
1253     * @param conn The connection to use.
1254     *
1255     * @return Whether or not we were successful.
1256     *
1257     * @exception SQLException Thrown if some unexpected error happens
1258     */

1259    static boolean getMetaDataTests( Connection JavaDoc conn)
1260        throws SQLException JavaDoc
1261    {
1262        boolean passed = true;
1263        PreparedStatement JavaDoc ps_f_r = null; // forward only, read only
1264
ResultSet JavaDoc rs;
1265        ResultSetMetaData JavaDoc rsmd_ps;
1266        ResultSetMetaData JavaDoc rsmd_rs;
1267        SQLWarning JavaDoc warning;
1268
1269
1270        ps_f_r = conn.prepareStatement(
1271                                     "select c50, i, 43 from t",
1272                                     ResultSet.TYPE_FORWARD_ONLY,
1273                                     ResultSet.CONCUR_READ_ONLY);
1274
1275        rsmd_ps = ps_f_r.getMetaData();
1276        if (rsmd_ps == null)
1277        {
1278            System.out.println("rsmd_ps expected to be non-null");
1279            return false;
1280        }
1281
1282        // Now get meta data from result set
1283
rs = ps_f_r.executeQuery();
1284        rsmd_rs = rs.getMetaData();
1285        if (rsmd_rs == null)
1286        {
1287            System.out.println("rsmd_rs expected to be non-null");
1288            return false;
1289        }
1290
1291        // check column count
1292
if (rsmd_ps.getColumnCount() != rsmd_rs.getColumnCount())
1293        {
1294            System.out.println("column count expected to be same, not " +
1295                               rsmd_ps.getColumnCount() +
1296                               " and " +
1297                               rsmd_rs.getColumnCount());
1298            passed = false;
1299        }
1300
1301        // get column name for 2nd column
1302
if (! rsmd_ps.getColumnName(2).equals(rsmd_rs.getColumnName(2)))
1303        {
1304            System.out.println("column name expected to be same, not " +
1305                               rsmd_ps.getColumnName(2) +
1306                               " and " +
1307                               rsmd_rs.getColumnName(2));
1308            passed = false;
1309        }
1310
1311        if (rsmd_ps.isReadOnly(2) != rsmd_rs.isReadOnly(2))
1312        {
1313            System.out.println("isReadOnly() expected to be same, not " +
1314                               rsmd_ps.isReadOnly(2) +
1315                               " and " +
1316                               rsmd_rs.isReadOnly(2));
1317            passed = false;
1318        }
1319        
1320        rs.close();
1321        ps_f_r.close();
1322
1323        return passed;
1324    }
1325
1326        
1327    /**
1328     * Tests for maxRow and fetchSize with scrollable cursors
1329     *
1330     * @param conn The connection to use.
1331         * @param maxRows The maxRows value to use
1332         * @param fetchSize The fetchSize value to use
1333     *
1334     * @return Whether or not we were successful.
1335     *
1336     * @exception SQLException Thrown if some unexpected error happens
1337     */

1338        private static boolean scrollVerifyMaxRowWithFetchSize(Connection JavaDoc conn, int maxRows, int fetchSize) {
1339            ResultSet JavaDoc rs;
1340            boolean passed = true;
1341            Statement JavaDoc s_i_r = null;
1342
1343            try {
1344                s_i_r = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
1345                        ResultSet.CONCUR_READ_ONLY);
1346                s_i_r.setMaxRows(maxRows);
1347
1348                // Execute query
1349
rs = s_i_r.executeQuery("values 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15");
1350                rs.setFetchSize(fetchSize);
1351
1352                // this should not affect the ResultSet because
1353
s_i_r.setMaxRows(2);
1354                if (maxRows == 0)
1355                    maxRows = 15;
1356
1357                if (rs == null)
1358                {
1359                        System.out.println("rs expected to be non-null.");
1360                        passed = false;
1361                }
1362                // Start from before first
1363
// Iterate straight thru RS, expect only maxRows rows.
1364
for (int index = 1; index < maxRows + 1; index++)
1365                {
1366                        if (! rs.next())
1367                        {
1368                                System.out.println("rs.next() failed, index = " + index);
1369                                passed = false;
1370                                break;
1371                        } else {
1372                                if (index != rs.getInt(1)) {
1373                                    System.out.println("Expected: " + index +
1374                                            " not: " + rs.getInt(1));
1375                                }
1376                        }
1377                }
1378                // We should not see another row (only maxRows, not total)
1379
if (rs.next())
1380                {
1381                        System.out.println("Error with maxRows = " + maxRows +
1382                                " and fetchSize = " + fetchSize + "\n" +
1383                                "rs.next() failed, should not have seen " +
1384                                (maxRows + 1) + "th row.");
1385                        passed = false;
1386                }
1387
1388                // Start from first and verify maxRows
1389
if (!rs.first())
1390                {
1391                        System.out.println("rs.first() failed.");
1392                        passed = false;
1393                }
1394                // Iterate forward thru RS, expect only (maxRows - 1) more rows.
1395
for (int index = 1; index < maxRows; index++)
1396                {
1397                        if (! rs.next())
1398                        {
1399                                System.out.println("rs.previous() failed, index = " +
1400                                        index);
1401                                passed = false;
1402                                break;
1403                        } else {
1404                                if ((index + 1) != rs.getInt(1))
1405                                    System.out.println("Error with maxRows = " +
1406                                            maxRows + " and fetchSize = " +
1407                                            fetchSize + "\n" + "Error with maxRows = " +
1408                                            maxRows + " and fetchSize = " + fetchSize +
1409                                            "\n" + "Expected: " + (index + 1) +
1410                                            " not: " + rs.getInt(1));
1411                        }
1412                }
1413                // We should not see another row (only maxRows, not total)
1414
if (rs.next())
1415                {
1416                        System.out.println("Error with maxRows = " + maxRows +
1417                                " and fetchSize = " + fetchSize + "\n" +
1418                                "rs.next() failed, should not have seen " +
1419                                (maxRows + 1) + "th row.");
1420                        passed = false;
1421                }
1422
1423                // Start from afterLast and verify maxRows
1424
rs.afterLast();
1425                // Iterate backwards thru RS, expect only (maxRows - 1) rows.
1426
for (int index = 1; index < maxRows + 1; index++)
1427                {
1428                        if (! rs.previous())
1429                        {
1430                                System.out.println("rs.previous() failed, index = " +
1431                                        index);
1432                                passed = false;
1433                                break;
1434                        } else {
1435                                if (((maxRows - index) + 1) != rs.getInt(1)) {
1436                                    System.out.println("Error with maxRows = " + maxRows +
1437                                            " and fetchSize = " + fetchSize + "\n" +
1438                                            "Expected: " + ((maxRows - index) + 1) +
1439                                            " not: " + rs.getInt(1));
1440                                }
1441                        }
1442                }
1443                // We should not see another row (only maxRows, not total)
1444
if (rs.previous())
1445                {
1446                        System.out.println("Error with maxRows = " + maxRows +
1447                                " and fetchSize = " + fetchSize + "\n" +
1448                                "rs.previous() failed, should not have seen " +
1449                                (maxRows + 1) + "th row.");
1450                        passed = false;
1451                }
1452
1453                // Start from last and verify maxRows
1454
if (!rs.last())
1455                {
1456                        System.out.println("rs.last() failed.");
1457                        passed = false;
1458                }
1459                // Iterate backwards thru RS, expect only (maxRows - 1) more rows.
1460
for (int index = 1; index < maxRows; index++)
1461                {
1462                        if (! rs.previous())
1463                        {
1464                                System.out.println("rs.previous() failed, index = " +
1465                                        index);
1466                                passed = false;
1467                                break;
1468                        } else {
1469                                if ((maxRows - index) != rs.getInt(1)) {
1470                                    System.out.println("Error with maxRows = " + maxRows +
1471                                            " and fetchSize = " + fetchSize + "\n" +
1472                                            "Expected: " + (maxRows - index) + " not: " +
1473                                            rs.getInt(1));
1474                                }
1475                        }
1476                }
1477                // We should not see another row (only 5, not 6)
1478
if (rs.previous())
1479                {
1480                        System.out.println("Error with maxRows = " + maxRows +
1481                                " and fetchSize = " + fetchSize + "\n" +
1482                                "rs.previous() failed, should not have seen " +
1483                                (maxRows + 1) + "th row.");
1484                        passed = false;
1485                }
1486
1487                rs.last();
1488                int rows = rs.getRow();
1489                
1490                rs.absolute(rows/2);
1491                if (rs.relative(-1 * (rows))) {
1492                    System.out.println("relative(" + -1 * (rows) + ") should return false, position outside of the resultSet");
1493                    
1494                }
1495                if (!rs.isBeforeFirst()) {
1496                    System.out.println("isBeforeFirst should be true");
1497                }
1498
1499                rs.absolute(rows/2);
1500                if (rs.relative(rows)) {
1501                    System.out.println("relative(" + (rows) + ") should return false, position outside of the resultSet");
1502                }
1503                if (!rs.isAfterLast()) {
1504                    System.out.println("isAfterLast should be true");
1505                }
1506                rs.absolute(rows/2);
1507                if (rs.absolute(rows + 1)) {
1508                    System.out.println("absolute(" + (rows + 1) + ") should return false, position outside of the resultSet");
1509                    System.out.println("Current row: " + rs.getInt(1));
1510                }
1511                if (!rs.isAfterLast()) {
1512                    System.out.println("isAfterLast should be true");
1513                }
1514                rs.absolute(rows/2);
1515                if (rs.absolute((-1) * (rows + 1))) {
1516                    System.out.println("absolute(" + (((-1) * (rows + 1))) + ") should return false, position outside of the resultSet");
1517                    System.out.println("Current row: " + rs.getInt(1));
1518                }
1519                if (!rs.isBeforeFirst()) {
1520                    System.out.println("isBeforeFirst should be true");
1521                }
1522
1523                rs.close();
1524            
1525            } catch (SQLException JavaDoc e) {
1526                System.out.println(e.getMessage());
1527            }
1528
1529            return passed;
1530        }
1531
1532
1533        
1534    /**
1535     * Check to make sure that the given SQLException is an exception
1536     * with the expected sqlstate.
1537     *
1538     * @param e The SQLException to check
1539     * @param SQLState The sqlstate to look for
1540     *
1541     * @return true means the exception is the expected one
1542     */

1543
1544    private static boolean checkException(SQLException JavaDoc e,
1545                                            String JavaDoc SQLState)
1546    {
1547        String JavaDoc state;
1548        String JavaDoc nextState;
1549        SQLException JavaDoc next;
1550        boolean passed = true;
1551
1552        state = e.getSQLState();
1553
1554
1555        if (! SQLState.equals(state)) {
1556                System.out.println("FAIL -- unexpected exception " + e +
1557                    "sqlstate: " + state + SQLState);
1558                passed = false;
1559            }
1560
1561        return passed;
1562    }
1563
1564    /**
1565     * Clean up after ourselves when testing is done.
1566     *
1567     * @param conn The Connection
1568     * @param s A Statement on the Connection
1569     *
1570     * @return true if it succeeds, false if it doesn't
1571     *
1572     * @exception SQLException Thrown if some unexpected error happens
1573     */

1574
1575    static boolean cleanUp(Connection JavaDoc conn, Statement JavaDoc s) {
1576        try {
1577            /* Drop the table we created */
1578            if (s == null)
1579            {
1580                // well, then, we'll have to restart
1581
s = conn.createStatement();
1582            }
1583            s.execute("drop table t");
1584            /* Close the connection */
1585            conn.commit();
1586            conn.close();
1587        } catch (Throwable JavaDoc e) {
1588            System.out.println("FAIL -- unexpected exception caught in cleanup()");
1589            JDBCDisplayUtil.ShowException(System.out, e);
1590            return false;
1591        }
1592
1593        return true;
1594    }
1595
1596    /*
1597     * cleanup also before test start, just in case
1598     * @param conn The Connection
1599     */

1600    static void cleanUp(Connection JavaDoc conn) throws SQLException JavaDoc {
1601        Statement JavaDoc cleanupStmt = conn.createStatement();
1602        String JavaDoc[] testObjects = {"table t"};
1603        TestUtil.cleanUpTest(cleanupStmt, testObjects);
1604        cleanupStmt.close();
1605    }
1606
1607
1608}
1609
Popular Tags