KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derbyTesting.functionTests.tests.lang.repeat
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.sql.Connection JavaDoc;
25 import java.sql.DriverManager JavaDoc;
26 import java.sql.Statement JavaDoc;
27 import java.sql.PreparedStatement JavaDoc;
28 import java.sql.ResultSet JavaDoc;
29 import java.sql.ResultSetMetaData JavaDoc;
30 import java.sql.SQLException JavaDoc;
31 import java.sql.SQLWarning JavaDoc;
32
33 import org.apache.derby.tools.ij;
34
35 /**
36     Test the statement cache -- reusing statements with the
37     matching SQL text. The only way to verify this output
38     is to look at the log file for StatementCache debug flag
39     messages about accesses.
40     <p>
41     The one concrete test here is that the statements
42     are actually dumped when the connection is closed,
43     and attempts to execute them will fail.
44
45     @author ames
46  */

47
48 public class repeat {
49
50
51     public static void main(String JavaDoc[] args) {
52         System.out.println("Test repeat starting");
53         boolean passed = false;
54         try {
55             Connection JavaDoc conn;
56
57             // use the ij utility to read the property file and
58
// make the initial connection.
59
ij.getPropertyArg(args);
60             conn = ij.startJBMS();
61
62             Statement JavaDoc s = conn.createStatement();
63             s.execute("create table t (i int)");
64
65             s.execute("insert into t values(180)");
66
67             // should find statement in cache:
68
s.execute("insert into t values(180)");
69
70             // should find statement in cache:
71
PreparedStatement JavaDoc ps1 = conn.prepareStatement("insert into t values(180)");
72
73             for (int i=1; i<=2; i++) {
74                 int rows = ps1.executeUpdate();
75
76                 if (rows != 1)
77                     System.out.println("FAIL -- insert wrong number of rows");
78             }
79
80             conn.close();
81
82             try {
83                 int rows = ps1.executeUpdate();
84             } catch (Throwable JavaDoc e) {
85                 passed = true;
86             }
87             if (!passed)
88                 System.out.println("FAIL -- able to insert after disconnect");
89
90         } catch (Throwable JavaDoc e) {
91             e.printStackTrace();
92         }
93
94         if (passed)
95             System.out.println("PASS");
96         System.out.println("Test repeat finished");
97     }
98 }
99
100
Popular Tags