KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > functionTests > tests > derbynet > executeUpdate


1 /*
2
3    Derby - Class org.apache.derbyTesting.functionTests.tests.derbynet.executeUpdate
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.derbynet;
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
30 import org.apache.derby.tools.ij;
31 /**
32     This test tests the JDBC Statement executeUpdate method. Since IJ will eventually
33     just use execute rather then executeUpdate, I want to make sure that executeUpdate
34     is minimally covered.
35 */

36
37 public class executeUpdate
38 {
39
40     public static void main (String JavaDoc args[])
41     {
42         try
43         {
44             System.out.println("executeUpdate Test Starts");
45             // Initialize JavaCommonClient Driver.
46
ij.getPropertyArg(args);
47             Connection JavaDoc conn = ij.startJBMS();
48             
49             if (conn == null)
50             {
51                 System.out.println("conn didn't work");
52                 return;
53             }
54             Statement JavaDoc stmt = conn.createStatement();
55             int rowCount = stmt.executeUpdate("create table exup(a int)");
56             if (rowCount != 0)
57                 System.out.println("FAIL - non zero return count on create table");
58             else
59                 System.out.println("PASS - create table");
60             rowCount = stmt.executeUpdate("insert into exup values(1)");
61             if (rowCount != 1)
62                 System.out.println("FAIL - expected row count 1, got " + rowCount);
63             else
64                 System.out.println("PASS - insert 1 row");
65             rowCount = stmt.executeUpdate("insert into exup values(2),(3),(4)");
66             if (rowCount != 3)
67                 System.out.println("FAIL - expected row count 3, got " + rowCount);
68             else
69                 System.out.println("PASS - insert 3 rows");
70             System.out.println("Rows in table should be 1,2,3,4");
71             ResultSet JavaDoc rs = stmt.executeQuery("select * from exup");
72             int i = 1;
73             boolean fail = false;
74             int val;
75             while (rs.next())
76             {
77                 if (i++ != (val = rs.getInt(1)))
78                 {
79                     System.out.println("FAIL - expecting " + i + " got " + val);
80                     fail = true;
81                 }
82             }
83             if (i != 5)
84                 System.out.println("FAIL - too many rows in table");
85             else if (!fail)
86                 System.out.println("PASS - correct rows in table");
87             rs.close();
88             rowCount = stmt.executeUpdate("drop table exup");
89             if (rowCount != 0)
90                 System.out.println("FAIL - non zero return count on drop table");
91             else
92                 System.out.println("PASS - drop table");
93             stmt.close();
94             System.out.println("executeUpdate Test ends");
95
96         }
97         catch (java.sql.SQLException JavaDoc e) {
98                 e.printStackTrace();
99         }
100         catch (Exception JavaDoc e)
101         {
102             e.printStackTrace();
103         }
104     }
105 }
106
Popular Tags