1 20 package org.apache.derbyTesting.functionTests.tests.jdbcapi; 21 22 import org.apache.derbyTesting.functionTests.util.SQLStateConstants; 23 import org.apache.derbyTesting.junit.BaseJDBCTestCase; 24 import org.apache.derbyTesting.junit.JDBC; 25 26 import junit.framework.*; 27 28 import java.sql.*; 29 30 46 public class ScrollResultSetTest extends BaseJDBCTestCase { 47 48 49 public ScrollResultSetTest(String name) { 50 super(name); 51 } 52 53 public static Test suite() { 54 TestSuite suite = new TestSuite(); 55 56 if (JDBC.vmSupportsJDBC3() || JDBC.vmSupportsJSR169()) { 58 suite.addTestSuite(ScrollResultSetTest.class); 59 } 60 61 return suite; 62 } 63 64 67 public void setUp() throws Exception { 68 Connection con = getConnection(); 69 con.setAutoCommit(true); 70 71 String createTableWithPK = "CREATE TABLE tableWithPK (" + 72 "c1 int primary key," + 73 "c2 int)"; 74 String insertData = "INSERT INTO tableWithPK values " + 75 "(1, 1), (2, 2), (3, 3), (4, 4), (5, 5)"; 76 Statement stmt = con.createStatement(); 77 stmt.execute(createTableWithPK); 78 79 stmt.execute(insertData); 80 stmt.close(); 81 } 82 83 86 public void tearDown() throws Exception { 87 println("TearDown"); 88 Statement s = getConnection().createStatement(); 89 try { 90 91 s.executeUpdate("DROP TABLE tableWithPK"); 92 } catch (SQLException e) { 93 printStackTrace(e); 94 } 95 s.close(); 96 super.tearDown(); 97 98 } 99 100 104 public void testNextOnLastRowForwardOnly() throws SQLException{ 105 106 Connection con = getConnection(); 107 con.setAutoCommit(true); 108 con.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT); 109 Statement roStmt = con.createStatement( 110 ResultSet.TYPE_FORWARD_ONLY, 111 ResultSet.CONCUR_READ_ONLY); 112 113 ResultSet rs = roStmt.executeQuery("SELECT c1 FROM tableWithPK"); 114 115 while (rs.next()); 117 118 try { 119 rs.next(); 122 assertTrue("Excepted exception to be thrown - result set is closed", 123 false); 124 } catch (SQLException se) { 125 if (!usingDerbyNet()) { 126 assertSQLState("Unexpected SQL State", 127 SQLStateConstants.RESULT_SET_IS_CLOSED, se); 128 } 129 } 130 131 } 132 133 137 public void testNextOnLastRowScrollable() throws SQLException{ 138 139 Connection con = getConnection(); 140 con.setAutoCommit(true); 141 con.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT); 142 Statement roStmt = con.createStatement( 143 ResultSet.TYPE_SCROLL_INSENSITIVE, 144 ResultSet.CONCUR_READ_ONLY); 145 146 ResultSet rs = roStmt.executeQuery("SELECT c1 FROM tableWithPK"); 147 rs.last(); 149 rs.next(); 150 151 assertFalse("Calling next while positioned after last returns " + 154 "false", rs.next()); 155 assertTrue("Moving to absolute(2) returns true", rs.absolute(2)); 156 rs.close(); 157 158 } 159 160 } 161 | Popular Tags |