KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > functionTests > tests > jdbcapi > SetQueryTimeoutTest


1 /*
2
3    Derby - Class org.apache.derbyTesting.functionTests.tests.lang.SetQueryTimeoutTest
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.jdbcapi;
23
24 import java.sql.CallableStatement JavaDoc;
25 import java.sql.Connection JavaDoc;
26 import java.sql.SQLException JavaDoc;
27 import java.sql.Statement JavaDoc;
28 import java.sql.PreparedStatement JavaDoc;
29 import java.sql.ResultSet JavaDoc;
30
31 import java.util.Collection JavaDoc;
32 import java.util.HashSet JavaDoc;
33 import java.util.Collections JavaDoc;
34
35 import org.apache.derby.tools.ij;
36
37 /**
38  * Functional test for the Statement.setQueryTimeout() method.
39  *
40  * This test consists of four parts:
41  *
42  * 1. Executes a SELECT query in 4 different threads concurrently.
43  * The query calls a user-defined, server-side function which
44  * delays the execution, so that it takes several seconds even
45  * though the data volume is really low. The fetch operations
46  * take longer time than the timeout value set. Hence, this part
47  * tests getting timeouts from calls to ResultSet.next().
48  *
49  * Two connections are used, two threads execute their statement
50  * in the context of one connection, the other two threads in the
51  * context of the other connection. Of the 4 threads, only one
52  * executes its statement with a timeout value. This way, the test
53  * ensures that the correct statement is affected by setQueryTimeout(),
54  * regardless of what connection/transaction it and other statements
55  * are executed in the context of.
56  *
57  * 2. Executes an INSERT query in multiple threads.
58  * This part tests getting timeouts from calls to Statement.execute().
59  * Each thread executes the query in the context of a separate
60  * connection. There is no point in executing multiple statements
61  * on the same connection; since only one statement per connection
62  * executes at a time, there will be no interleaving of execution
63  * between them (contrary to the first part of this test, where
64  * calls to ResultSet.next() may be interleaved between the different
65  * threads).
66  *
67  * Half of the threads execute their statement with a timeout value set,
68  * this is to verify that the correct statements are affected by the
69  * timeout, while the other statements execute to completion.
70  *
71  * 3. Sets an invalid (negative) timeout. Verifies that the correct
72  * exception is thrown.
73  *
74  * 4. Tests that the query timeout value is not forgotten after the execution
75  * of a statement (DERBY-1692).
76  */

77 public class SetQueryTimeoutTest
78 {
79     private static final int TIMEOUT = 1; // In seconds
80
private static final int CONNECTIONS = 100;
81
82     private static void printSQLException(SQLException JavaDoc e)
83     {
84         while (e != null)
85         {
86             e.printStackTrace();
87             e = e.getNextException();
88         }
89     }
90
91     /**
92      * This Exception class is used for getting fail-fast behaviour in
93      * this test. There is no point in wasting cycles running a test to
94      * the end when we know that it has failed.
95      *
96      * In order to enable chaining of exceptions in J2ME, this class defines
97      * its own "cause", duplicating existing functionality in J2SE.
98      */

99     private static class TestFailedException
100         extends
101             Exception JavaDoc
102     {
103         private Throwable JavaDoc cause;
104
105         public TestFailedException(Throwable JavaDoc t)
106         {
107             super();
108             cause = t;
109         }
110         
111         public TestFailedException(String JavaDoc message)
112         {
113             super(message);
114             cause = null;
115         }
116         
117         public TestFailedException(String JavaDoc message, Throwable JavaDoc t)
118         {
119             super(message);
120             cause = t;
121         }
122         
123         public String JavaDoc toString()
124         {
125             if (cause != null) {
126                 return super.toString() + ": " + cause.toString();
127             } else {
128                 return super.toString();
129             }
130         }
131         
132         public void printStackTrace()
133         {
134             super.printStackTrace();
135             if (cause != null) {
136                 if (cause instanceof SQLException JavaDoc) {
137                     SetQueryTimeoutTest.printSQLException((SQLException JavaDoc)cause);
138                 } else {
139                     cause.printStackTrace();
140                 }
141             }
142         }
143     }
144
145     /**
146      * Used for executing the SQL statements for setting up this test
147      * (the preparation phase). The queries testing setQueryTimeout()
148      * are run by the StatementExecutor class.
149      */

150     private static void exec(Connection JavaDoc connection,
151                              String JavaDoc queryString,
152                              Collection JavaDoc ignoreExceptions)
153         throws
154             TestFailedException
155     {
156         Statement JavaDoc statement = null;
157         try {
158             statement = connection.createStatement();
159             statement.execute(queryString);
160         } catch (SQLException JavaDoc e) {
161             String JavaDoc sqlState = e.getSQLState();
162             if (!ignoreExceptions.contains(sqlState)) {
163                 throw new TestFailedException(e); // See finally block below
164
}
165         } finally {
166             if (statement != null) {
167                 try {
168                     statement.close();
169                 } catch (SQLException JavaDoc ee) {
170                     // This will discard an exception possibly thrown above :-(
171
// But we don't worry too much about this, since:
172
// 1. This is just a test
173
// 2. We don't expect close() to throw
174
// 3. If it does, this will be inspected by a developer
175
throw new TestFailedException(ee);
176                 }
177             }
178         }
179     }
180
181     // Convenience method
182
private static void exec(Connection JavaDoc connection,
183                              String JavaDoc queryString)
184         throws
185             TestFailedException
186     {
187         exec(connection, queryString, Collections.EMPTY_SET);
188     }
189     
190     private static void dropTables(Connection JavaDoc conn, String JavaDoc tablePrefix)
191         throws
192             TestFailedException
193     {
194         Collection JavaDoc ignore = new HashSet JavaDoc();
195         ignore.add("42Y55");
196         
197         exec(conn, "drop table " + tablePrefix + "_orig", ignore);
198         exec(conn, "drop table " + tablePrefix + "_copy", ignore);
199     }
200     
201     private static void prepareTables(Connection JavaDoc conn, String JavaDoc tablePrefix)
202         throws
203             TestFailedException
204     {
205         System.out.println("Initializing tables with prefix " + tablePrefix);
206
207         dropTables(conn, tablePrefix);
208         
209         exec(conn,
210              "create table " + tablePrefix + "_orig (a int)");
211
212         exec(conn,
213              "create table " + tablePrefix + "_copy (a int)");
214
215         exec(conn,
216              "insert into "
217              + tablePrefix + "_orig"
218              + " values(0),(1),(2),(3),(4),(5),(6)");
219     }
220
221     /**
222      * This is the user-defined function which is called from our queries
223      */

224     public static int delay(int seconds, int value)
225         throws
226             SQLException JavaDoc
227     {
228         try {
229             Thread.sleep(seconds * 1000);
230         } catch (InterruptedException JavaDoc e) {
231             // Ignore
232
}
233         return value;
234     }
235
236     private static void prepareForTimedQueries(Connection JavaDoc conn)
237         throws
238             TestFailedException
239     {
240         System.out.println("Preparing for testing queries with timeout");
241
242         try {
243             conn.setAutoCommit(true);
244         } catch (SQLException JavaDoc e) {
245             throw new TestFailedException("Should not happen", e);
246         }
247         
248         try {
249             exec(conn, "DROP FUNCTION DELAY");
250         } catch (Exception JavaDoc e) {
251             // Ignore
252
}
253
254         exec(conn, "CREATE FUNCTION DELAY(SECONDS INTEGER, VALUE INTEGER) RETURNS INTEGER PARAMETER STYLE JAVA NO SQL LANGUAGE JAVA EXTERNAL NAME 'org.apache.derbyTesting.functionTests.tests.jdbcapi.SetQueryTimeoutTest.delay'");
255
256         prepareTables(conn, "t");
257     }
258     
259     private static String JavaDoc getFetchQuery(String JavaDoc tablePrefix)
260     {
261         /**
262          * The reason for using the mod function here is to force
263          * at least one invocation of ResultSet.next() to read
264          * more than one row from the table before returning.
265          * This is necessary since timeout is checked only when
266          * reading rows from base tables, and when the first row
267          * is read, the query still has not exceeded the timeout.
268          */

269         return "select a from " + tablePrefix + "_orig where mod(DELAY(1,a),3)=0";
270     }
271     
272     private static String JavaDoc getExecQuery(String JavaDoc tablePrefix)
273     {
274         return "insert into "
275             + tablePrefix + "_copy select a from "
276             + tablePrefix + "_orig where DELAY(1,1)=1";
277     }
278     
279     private static class StatementExecutor
280         extends
281             Thread JavaDoc
282     {
283         private PreparedStatement JavaDoc statement;
284         private boolean doFetch;
285         private int timeout;
286         private SQLException JavaDoc sqlException;
287         private String JavaDoc name;
288         private long highestRunTime;
289         
290         public StatementExecutor(PreparedStatement JavaDoc statement,
291                                  boolean doFetch,
292                                  int timeout)
293         {
294             this.statement = statement;
295             this.doFetch = doFetch;
296             this.timeout = timeout;
297             highestRunTime = 0;
298             sqlException = null;
299             if (timeout > 0) {
300                 try {
301                     statement.setQueryTimeout(timeout);
302                 } catch (SQLException JavaDoc e) {
303                     sqlException = e;
304                 }
305             }
306         }
307         
308         private void setHighestRunTime(long runTime)
309         {
310             synchronized (this) {
311                 highestRunTime = runTime;
312             }
313         }
314         
315         public long getHighestRunTime()
316         {
317             synchronized (this) {
318                 return highestRunTime;
319             }
320         }
321         
322         private boolean fetchRow(ResultSet JavaDoc resultSet)
323             throws
324                 SQLException JavaDoc
325         {
326             long startTime = System.currentTimeMillis();
327             boolean hasNext = resultSet.next();
328             long endTime = System.currentTimeMillis();
329             long runTime = endTime - startTime;
330             if (runTime > highestRunTime) setHighestRunTime(runTime);
331             return hasNext;
332         }
333
334         public void run()
335         {
336             if (sqlException != null)
337                 return;
338
339             ResultSet JavaDoc resultSet = null;
340
341             try {
342                 if (doFetch) {
343                     long startTime = System.currentTimeMillis();
344                     resultSet = statement.executeQuery();
345                     long endTime = System.currentTimeMillis();
346                     setHighestRunTime(endTime - startTime);
347                     while (fetchRow(resultSet)) {
348                         yield();
349                     }
350                 } else {
351                     long startTime = System.currentTimeMillis();
352                     statement.execute();
353                     long endTime = System.currentTimeMillis();
354                     setHighestRunTime(endTime - startTime);
355                 }
356             } catch (SQLException JavaDoc e) {
357                 synchronized (this) {
358                     sqlException = e;
359                 }
360             } finally {
361                 if (resultSet != null) {
362                     try {
363                         resultSet.close();
364                     } catch (SQLException JavaDoc ex) {
365                         if (sqlException != null) {
366                             System.err.println("Discarding previous exception");
367                             sqlException.printStackTrace();
368                         }
369                         sqlException = ex;
370                     }
371                 }
372             }
373         }
374
375         public SQLException JavaDoc getSQLException()
376         {
377             synchronized (this) {
378                 return sqlException;
379             }
380         }
381     }
382
383     /**
384      * This method compares a thrown SQLException's SQLState value
385      * to an expected SQLState. If they do not match, a
386      * TestFailedException is thrown with the given message string.
387      */

388     private static void expectException(String JavaDoc expectSqlState,
389                                         SQLException JavaDoc sqlException,
390                                         String JavaDoc failMsg)
391         throws
392             TestFailedException
393     {
394         if (sqlException == null) {
395             throw new TestFailedException(failMsg);
396         } else {
397             String JavaDoc sqlState = sqlException.getSQLState();
398             if (!expectSqlState.equals(sqlState)) {
399                 throw new TestFailedException(sqlException);
400             }
401         }
402     }
403
404     // A convenience method which wraps a SQLException
405
private static PreparedStatement JavaDoc prepare(Connection JavaDoc conn, String JavaDoc query)
406         throws
407             TestFailedException
408     {
409         try {
410             return conn.prepareStatement(query);
411         } catch (SQLException JavaDoc e) {
412             throw new TestFailedException(e);
413         }
414     }
415
416     /**
417      * Part 1 of this test.
418      */

419     private static void testTimeoutWithFetch(Connection JavaDoc conn1,
420                                              Connection JavaDoc conn2)
421         throws
422             TestFailedException
423     {
424         System.out.println("Testing timeout with fetch operations");
425
426         try {
427             conn1.setAutoCommit(false);
428             conn2.setAutoCommit(false);
429         } catch (SQLException JavaDoc e) {
430             throw new TestFailedException("Should not happen", e);
431         }
432         
433         // The idea with these 4 statements is as follows:
434
// A - should time out
435
// B - different stmt on the same connection; should NOT time out
436
// C - different stmt on different connection; should NOT time out
437
// D - here just to create equal contention on conn1 and conn2
438

439         PreparedStatement JavaDoc statementA = prepare(conn1, getFetchQuery("t"));
440         PreparedStatement JavaDoc statementB = prepare(conn1, getFetchQuery("t"));
441         PreparedStatement JavaDoc statementC = prepare(conn2, getFetchQuery("t"));
442         PreparedStatement JavaDoc statementD = prepare(conn2, getFetchQuery("t"));
443
444         StatementExecutor[] statementExecutor = new StatementExecutor[4];
445         statementExecutor[0] = new StatementExecutor(statementA, true, TIMEOUT);
446         statementExecutor[1] = new StatementExecutor(statementB, true, 0);
447         statementExecutor[2] = new StatementExecutor(statementC, true, 0);
448         statementExecutor[3] = new StatementExecutor(statementD, true, 0);
449         
450         for (int i = 3; i >= 0; --i) {
451             statementExecutor[i].start();
452         }
453         
454         for (int i = 0; i < 4; ++i) {
455             try {
456                 statementExecutor[i].join();
457             } catch (InterruptedException JavaDoc e) {
458                 throw new TestFailedException("Should never happen", e);
459             }
460         }
461
462         /**
463          * Actually, there is no guarantee that setting a query timeout
464          * for a statement will actually cause a timeout, even if execution
465          * of the statement takes longer than the specified timeout.
466          *
467          * However, these queries execute significantly longer than the
468          * specified query timeout. Also, the cancellation mechanism
469          * implemented should be quite responsive. In sum, we expect
470          * the statement to always time out.
471          *
472          * If it does not time out, however, we print the highest
473          * execution time for the query, as an assistance in determining
474          * why it failed. Compare the number to the TIMEOUT constant
475          * in this class (note that the TIMEOUT constant is in seconds,
476          * while the execution time is in milliseconds).
477          */

478         expectException("XCL52",
479                         statementExecutor[0].getSQLException(),
480                         "fetch did not time out. Highest execution time: "
481                         + statementExecutor[0].getHighestRunTime() + " ms");
482
483         System.out.println("Statement 0 timed out");
484
485         for (int i = 1; i < 4; ++i) {
486             SQLException JavaDoc sqlException = statementExecutor[i].getSQLException();
487             if (sqlException != null) {
488                 throw new TestFailedException("Unexpected exception in " + i,
489                                               sqlException);
490             }
491             System.out.println("Statement " + i + " completed");
492         }
493
494         try {
495             statementA.close();
496             statementB.close();
497             statementC.close();
498             statementD.close();
499             conn1.commit();
500             conn2.commit();
501         } catch (SQLException JavaDoc e) {
502             throw new TestFailedException(e);
503         }
504     }
505
506     /**
507      * Part two of this test.
508      */

509     private static void testTimeoutWithExec(Connection JavaDoc[] connections)
510         throws
511             TestFailedException
512     {
513         System.out.println("Testing timeout with an execute operation");
514
515         for (int i = 0; i < connections.length; ++i) {
516             try {
517                 connections[i].setAutoCommit(true);
518             } catch (SQLException JavaDoc e) {
519                 throw new TestFailedException("Should not happen", e);
520             }
521         }
522
523         PreparedStatement JavaDoc statements[] = new PreparedStatement JavaDoc[connections.length];
524         for (int i = 0; i < statements.length; ++i) {
525             statements[i] = prepare(connections[i], getExecQuery("t"));
526         }
527
528         StatementExecutor[] executors = new StatementExecutor[statements.length];
529         for (int i = 0; i < executors.length; ++i) {
530             int timeout =
531                 (i % 2 == 0)
532                 ? TIMEOUT
533                 : 0;
534             executors[i] = new StatementExecutor(statements[i], false, timeout);
535         }
536
537         for (int i = 0; i < executors.length; ++i) {
538             executors[i].start();
539         }
540
541         for (int i = 0; i < executors.length; ++i) {
542             try {
543                 executors[i].join();
544             } catch (InterruptedException JavaDoc e) {
545                 throw new TestFailedException("Should never happen", e);
546             }
547         }
548         
549         /**
550          * Actually, there is no guarantee that setting a query timeout
551          * for a statement will actually cause a timeout, even if execution
552          * of the statement takes longer than the specified timeout.
553          *
554          * However, these queries execute significantly longer than the
555          * specified query timeout. Also, the cancellation mechanism
556          * implemented should be quite responsive. In sum, we expect
557          * the statement to always time out.
558          *
559          * If it does not time out, however, we print the highest
560          * execution time for the query, as an assistance in determining
561          * why it failed. Compare the number to the TIMEOUT constant
562          * in this class (note that the TIMEOUT constant is in seconds,
563          * while the execution time is in milliseconds).
564          */

565         for (int i = 0; i < executors.length; ++i) {
566             int timeout =
567                 (i % 2 == 0)
568                 ? TIMEOUT
569                 : 0;
570             if (timeout > 0) {
571                 expectException("XCL52",
572                                 executors[i].getSQLException(),
573                                 "exec did not time out. Execution time: "
574                                 + executors[i].getHighestRunTime() + " ms");
575             } else {
576                 SQLException JavaDoc sqlException = executors[i].getSQLException();
577                 if (sqlException != null) {
578                     throw new TestFailedException(sqlException);
579                 }
580             }
581         }
582
583         System.out.println("Statements that should time out timed out, and statements that should complete completed");
584
585         for (int i = 0; i < statements.length; ++i) {
586             try {
587                 statements[i].close();
588             } catch (SQLException JavaDoc e) {
589                 throw new TestFailedException(e);
590             }
591         }
592     }
593     
594     private static void testInvalidTimeoutValue(Connection JavaDoc conn)
595         throws
596             TestFailedException
597     {
598         System.out.println("Testing setting a negative timeout value");
599
600         try {
601             conn.setAutoCommit(true);
602         } catch (SQLException JavaDoc e) {
603             throw new TestFailedException("Should not happen", e);
604         }
605
606         // Create statement
607
PreparedStatement JavaDoc stmt = null;
608         try {
609             stmt = conn.prepareStatement("select * from sys.systables");
610         } catch (SQLException JavaDoc e) {
611             throw new TestFailedException("Should not happen", e);
612         }
613         
614         // Set (invalid) timeout value - expect exception
615
try {
616             stmt.setQueryTimeout(-1);
617         } catch (SQLException JavaDoc e) {
618             expectException("XJ074", e,
619                         "negative timeout value should give exception");
620         }
621         
622         System.out.println("Negative timeout value caused exception, as expected");
623         
624         // Execute the statement and fetch result
625
ResultSet JavaDoc rs = null;
626         try {
627             rs = stmt.executeQuery();
628             System.out.println("Execute returned a ResultSet");
629             rs.close();
630         } catch (SQLException JavaDoc e) {
631             throw new TestFailedException("Should not happen", e);
632         } finally {
633             try {
634                 stmt.close();
635             } catch (SQLException JavaDoc e) {
636                 // This will discard an exception possibly thrown above :-(
637
// But we don't worry too much about this, since:
638
// 1. This is just a test
639
// 2. We don't expect close() to throw
640
// 3. If it does, this will be inspected by a developer
641
throw new TestFailedException("close should not throw", e);
642             }
643         }
644     }
645
646     /** This tests timeout with executeUpdate call. */
647     private static void testTimeoutWithExecuteUpdate(Connection JavaDoc conn)
648         throws TestFailedException
649     {
650         System.out.println("Testing timeout with executeUpdate call.");
651         try{
652             Statement JavaDoc stmt = conn.createStatement();
653             stmt.setQueryTimeout(TIMEOUT);
654             stmt.executeUpdate(getExecQuery("t"));
655         } catch (SQLException JavaDoc sqle) {
656             expectException("XCL52", sqle, "Should have timed out.");
657         }
658     }
659     
660     /** Test for DERBY-1692. */
661     private static void testRememberTimeoutValue(Connection JavaDoc conn)
662         throws TestFailedException
663     {
664         String JavaDoc sql = getFetchQuery("t");
665         try {
666             Statement JavaDoc stmt = conn.createStatement();
667             testStatementRemembersTimeout(stmt);
668             PreparedStatement JavaDoc ps = conn.prepareStatement(sql);
669             testStatementRemembersTimeout(ps);
670             CallableStatement JavaDoc cs = conn.prepareCall(sql);
671             testStatementRemembersTimeout(cs);
672         } catch (SQLException JavaDoc sqle) {
673             throw new TestFailedException("Should not happen", sqle);
674         }
675     }
676
677     /** Test that a statement remembers its timeout value when executed
678      * multiple times. */

679     private static void testStatementRemembersTimeout(Statement JavaDoc stmt)
680         throws SQLException JavaDoc, TestFailedException
681     {
682         System.out.println("Testing that Statement remembers timeout.");
683         stmt.setQueryTimeout(1);
684         for (int i = 0; i < 3; i++) {
685             try {
686                 ResultSet JavaDoc rs = stmt.executeQuery(getFetchQuery("t"));
687                 while (rs.next());
688                 throw new TestFailedException("Should have timed out.");
689             } catch (SQLException JavaDoc sqle) {
690                 expectException("XCL52", sqle, "Should have timed out.");
691             }
692         }
693         stmt.close();
694     }
695
696     /** Test that a prepared statement remembers its timeout value when
697      * executed multiple times. */

698     private static void testStatementRemembersTimeout(PreparedStatement JavaDoc ps)
699         throws SQLException JavaDoc, TestFailedException
700     {
701         String JavaDoc name = (ps instanceof CallableStatement JavaDoc) ?
702             "CallableStatement" : "PreparedStatement";
703         System.out.println("Testing that " + name + " remembers timeout.");
704         ps.setQueryTimeout(1);
705         for (int i = 0; i < 3; i++) {
706             try {
707                 ResultSet JavaDoc rs = ps.executeQuery();
708                 while (rs.next());
709                 throw new TestFailedException("Should have timed out.");
710            } catch (SQLException JavaDoc sqle) {
711                 expectException("XCL52", sqle, "Should have timed out.");
712             }
713         }
714         ps.close();
715     }
716
717     /**
718      * Main program, makes this class invocable from the command line
719      */

720     public static void main(String JavaDoc[] args)
721     {
722         new SetQueryTimeoutTest().go(args);
723     }
724
725     /**
726      * The actual main bulk of this test.
727      * Sets up the environment, prepares tables,
728      * runs the tests, and shuts down.
729      */

730     public void go(String JavaDoc[] args)
731     {
732         System.out.println("Test SetQueryTimeoutTest starting");
733
734         Connection JavaDoc[] connections = new Connection JavaDoc[CONNECTIONS];
735         for (int i = 0; i < connections.length; ++i) {
736             connections[i] = null;
737         }
738
739         try {
740             // Load the JDBC Driver class
741
// use the ij utility to read the property file and
742
// create connections
743
ij.getPropertyArg(args);
744             for (int i = 0; i < connections.length; ++i) {
745                 connections[i] = ij.startJBMS();
746             }
747
748             System.out.println("Got connections");
749
750             for (int i = 0; i < connections.length; ++i) {
751                 connections[i].setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
752             }
753
754             prepareForTimedQueries(connections[0]);
755             testTimeoutWithFetch(connections[0], connections[1]);
756             testTimeoutWithExec(connections);
757             testInvalidTimeoutValue(connections[0]);
758             testRememberTimeoutValue(connections[0]);
759             testTimeoutWithExecuteUpdate(connections[0]);
760   
761             System.out.println("Test SetQueryTimeoutTest PASSED");
762         } catch (Throwable JavaDoc e) {
763             System.out.println("Test SetQueryTimeoutTest FAILED");
764             e.printStackTrace();
765         } finally {
766             for (int i = connections.length - 1; i >= 0; --i) {
767                 if (connections[i] != null) {
768                     try {
769                         connections[i].close();
770                     } catch (SQLException JavaDoc ex) {
771                         printSQLException(ex);
772                     }
773                 }
774             }
775             System.out.println("Closed connections");
776         }
777     }
778 }
779
Popular Tags