1 25 package testsuite.regression; 26 27 import java.lang.reflect.Method ; 28 import java.sql.ResultSet ; 29 30 import javax.sql.RowSet ; 31 32 import testsuite.BaseTestCase; 33 34 39 public class CachedRowsetTest extends BaseTestCase { 40 46 public CachedRowsetTest(String name) { 47 super(name); 48 } 49 50 55 public static void main(String [] args) { 56 junit.textui.TestRunner.run(CachedRowsetTest.class); 57 } 58 59 65 public void testBug5188() throws Exception { 66 String implClass = "com.sun.rowset.CachedRowSetImpl"; 67 Class c; 68 Method populate; 69 try { 70 c = Class.forName(implClass); 71 } catch (ClassNotFoundException e) { 72 System.out.println("skipping testBug5188. Requires: " + implClass); 73 return; 74 } 75 populate = c.getMethod("populate", new Class [] { ResultSet .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 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 RowSet cachedRowSet = (RowSet ) c.newInstance(); 93 populate.invoke(cachedRowSet, new Object [] { this.rs }); 95 96 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 |