KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > functionTests > util > StaticInitializers > InsertInStaticInitializer


1 /*
2
3    Derby - Class org.apache.derbyTesting.functionTests.util.StaticInitializers.InsertInStaticInitializer
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.util.StaticInitializers;
23
24 import java.sql.DriverManager JavaDoc;
25 import java.sql.Statement JavaDoc;
26 import java.sql.ResultSet JavaDoc;
27 import java.sql.SQLException JavaDoc;
28
29 /** Test Insert statement called from within static initializer holds
30  * onto locks it should hold onto and doesn't hold onto locks it shouldn't
31  * hold onto.
32 */

33 public class InsertInStaticInitializer
34 {
35
36     /* This is the method that is invoked from the outer query */
37     public static int getANumber()
38     {
39         return 1;
40     }
41
42     static
43     {
44         /* Execute a DML statement from within the static initializer */
45         doADMLStatement();
46     }
47
48     private static void doADMLStatement()
49     {
50         ResultSet JavaDoc rs = null;
51
52         try
53         {
54             int value;
55
56             /* Connect to the database */
57             Statement JavaDoc s = DriverManager.getConnection(
58                         "jdbc:default:connection").createStatement();
59
60             /* Execute a DML statement. This depends on t1 existing. */
61             boolean b = s.execute("INSERT into t1 values (1)");
62
63             //if (rs.next())
64
//{
65
// System.out.println("Value of t1.s is " + rs.getShort(1));
66
//}
67
}
68         catch (SQLException JavaDoc se)
69         {
70             System.out.println("Caught exception " + se);
71             se.printStackTrace(System.out);
72         }
73         finally
74         {
75             try
76             {
77                 if (rs != null)
78                     rs.close();
79             }
80             catch (SQLException JavaDoc se)
81             {
82                 System.out.println("Caught exception " + se);
83                 se.printStackTrace(System.out);
84             }
85         }
86     }
87 }
88
Popular Tags