KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > testsuite > regression > CachedRowsetTest


1 /*
2  Copyright (C) 2002-2004 MySQL AB
3
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of version 2 of the GNU General Public License as
6  published by the Free Software Foundation.
7
8  There are special exceptions to the terms and conditions of the GPL
9  as it is applied to this software. View the full text of the
10  exception in file EXCEPTIONS-CONNECTOR-J in the directory of this
11  software distribution.
12
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
22
23
24  */

25 package testsuite.regression;
26
27 import java.lang.reflect.Method JavaDoc;
28 import java.sql.ResultSet JavaDoc;
29
30 import javax.sql.RowSet JavaDoc;
31
32 import testsuite.BaseTestCase;
33
34 /**
35  * Regression test cases for the ResultSet class.
36  *
37  * @author Eric Herman
38  */

39 public class CachedRowsetTest extends BaseTestCase {
40     /**
41      * Creates a new CachedRowsetTest
42      *
43      * @param name
44      * the name of the test to run
45      */

46     public CachedRowsetTest(String JavaDoc name) {
47         super(name);
48     }
49
50     /**
51      * Runs all test cases in this test suite
52      *
53      * @param args
54      */

55     public static void main(String JavaDoc[] args) {
56         junit.textui.TestRunner.run(CachedRowsetTest.class);
57     }
58
59     /**
60      * Tests fix for BUG#5188, CachedRowSet errors using PreparedStatement. Uses
61      * Sun's "com.sun.rowset.CachedRowSetImpl"
62      *
63      * @throws Exception
64      */

65     public void testBug5188() throws Exception JavaDoc {
66         String JavaDoc implClass = "com.sun.rowset.CachedRowSetImpl";
67         Class JavaDoc c;
68         Method JavaDoc populate;
69         try {
70             c = Class.forName(implClass);
71         } catch (ClassNotFoundException JavaDoc e) {
72             System.out.println("skipping testBug5188. Requires: " + implClass);
73             return;
74         }
75         populate = c.getMethod("populate", new Class JavaDoc[] { ResultSet JavaDoc.class });
76
77         try {
78             this.stmt.executeUpdate("DROP TABLE IF EXISTS testBug5188");
79             this.stmt.executeUpdate("CREATE TABLE testBug5188 "
80                     + "(ID int NOT NULL AUTO_INCREMENT, "
81                     + "datafield VARCHAR(64), " + "PRIMARY KEY(ID))");
82
83             this.stmt.executeUpdate("INSERT INTO testBug5188(datafield) "
84                     + "values('test data stuff !')");
85
86             String JavaDoc sql = "SELECT * FROM testBug5188 where ID = ?";
87             this.pstmt = this.conn.prepareStatement(sql);
88             this.pstmt.setString(1, "1");
89             this.rs = this.pstmt.executeQuery();
90
91             // create a CachedRowSet and populate it
92
RowSet JavaDoc cachedRowSet = (RowSet JavaDoc) c.newInstance();
93             // cachedRowSet.populate(rs);
94
populate.invoke(cachedRowSet, new Object JavaDoc[] { this.rs });
95
96             // scroll through CachedRowSet ...
97
assertTrue(cachedRowSet.next());
98             assertEquals("1", cachedRowSet.getString("ID"));
99             assertEquals("test data stuff !", cachedRowSet
100                     .getString("datafield"));
101             assertFalse(cachedRowSet.next());
102         } finally {
103             this.stmt.executeUpdate("DROP TABLE IF EXISTS testBug5188");
104         }
105     }
106 }
Popular Tags