本文整理汇总了Java中javax.sql.rowset.FilteredRowSet.populate方法的典型用法代码示例。如果您正苦于以下问题:Java FilteredRowSet.populate方法的具体用法?Java FilteredRowSet.populate怎么用?Java FilteredRowSet.populate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.sql.rowset.FilteredRowSet
的用法示例。
在下文中一共展示了FilteredRowSet.populate方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCreateCopy
import javax.sql.rowset.FilteredRowSet; //导入方法依赖的package包/类
public void testCreateCopy() throws Exception {
FilteredRowSet filteredRowSet = newFilterRowSet();
rs = st.executeQuery("SELECT * FROM USER_INFO");
filteredRowSet.populate(rs);
Predicate range = new RangeOne();
filteredRowSet.setFilter(range);
if ("true".equals(System.getProperty("Testing Harmony"))) {
filteredRowSet.createCopy();
} else {
try {
filteredRowSet.createCopy();
fail("should throw SQLException");
} catch (SQLException e) {
// expected
}
}
}
示例2: testPopulate
import javax.sql.rowset.FilteredRowSet; //导入方法依赖的package包/类
public void testPopulate() throws Exception {
/*
* Set Filter before populate()
*/
RangeOne range = new RangeOne();
FilteredRowSet filteredRowSet = newFilterRowSet();
filteredRowSet.setFilter(range);
assertSame(range, filteredRowSet.getFilter());
rs = st.executeQuery("SELECT * FROM USER_INFO");
filteredRowSet.populate(rs);
assertTrue(filteredRowSet.first());
assertEquals(2, filteredRowSet.getInt(1));
filteredRowSet.setFilter(null);
assertTrue(filteredRowSet.first());
assertEquals(1, filteredRowSet.getInt(1));
}
示例3: testNextAndPrevious
import javax.sql.rowset.FilteredRowSet; //导入方法依赖的package包/类
public void testNextAndPrevious() throws Exception {
FilteredRowSet filteredRowSet = newFilterRowSet();
rs = st.executeQuery("SELECT * FROM USER_INFO");
filteredRowSet.populate(rs);
RangeOne range = new RangeOne();
filteredRowSet.setFilter(range);
assertTrue(filteredRowSet.next());
assertEquals(2, filteredRowSet.getInt(1));
assertEquals(EVALUATE_ROWSET, range.getTag());
assertEquals(2, range.getCount());
range.clear();
assertTrue(filteredRowSet.next());
assertEquals(3, filteredRowSet.getInt(1));
assertEquals(EVALUATE_ROWSET, range.getTag());
assertEquals(1, range.getCount());
range.clear();
assertTrue(filteredRowSet.previous());
assertEquals(2, filteredRowSet.getInt(1));
assertEquals(1, range.getCount());
range.clear();
assertFalse(filteredRowSet.previous());
assertEquals(EVALUATE_ROWSET, range.getTag());
}
示例4: testCreateShared
import javax.sql.rowset.FilteredRowSet; //导入方法依赖的package包/类
public void testCreateShared() throws Exception {
FilteredRowSet filteredRowSet = newFilterRowSet();
rs = st.executeQuery("SELECT * FROM USER_INFO");
filteredRowSet.populate(rs);
Predicate range = new RangeOne();
filteredRowSet.setFilter(range);
FilteredRowSet copyFilteredRs = (FilteredRowSet) filteredRowSet
.createShared();
assertSame(range, copyFilteredRs.getFilter());
}
示例5: testRelative
import javax.sql.rowset.FilteredRowSet; //导入方法依赖的package包/类
public void testRelative() throws Exception {
FilteredRowSet filteredRowSet = newFilterRowSet();
rs = st.executeQuery("SELECT * FROM USER_INFO");
filteredRowSet.populate(rs);
assertTrue(filteredRowSet.absolute(3));
assertEquals(3, filteredRowSet.getInt(1));
assertFalse(filteredRowSet.relative(2));
assertTrue(filteredRowSet.absolute(3));
assertEquals(3, filteredRowSet.getInt(1));
assertTrue(filteredRowSet.relative(1));
assertEquals(4, filteredRowSet.getInt(1));
assertTrue(filteredRowSet.absolute(3));
assertEquals(3, filteredRowSet.getInt(1));
assertTrue(filteredRowSet.relative(-1));
assertEquals(2, filteredRowSet.getInt(1));
assertFalse(filteredRowSet.relative(-2));
RangeOne range = new RangeOne();
filteredRowSet.setFilter(range);
filteredRowSet.beforeFirst();
assertTrue(filteredRowSet.relative(2));
assertEquals(3, filteredRowSet.getInt(1));
assertEquals(3, filteredRowSet.getRow());
assertFalse(filteredRowSet.relative(-2));
assertTrue(filteredRowSet.isBeforeFirst());
}
示例6: testNoFilter_Insert
import javax.sql.rowset.FilteredRowSet; //导入方法依赖的package包/类
public void testNoFilter_Insert() throws Exception {
FilteredRowSet filteredRowSet = newFilterRowSet();
rs = st.executeQuery("SELECT * FROM USER_INFO");
filteredRowSet.populate(rs);
/*
* TODO Call updateXXX() would throw NullPointerException on insert row
* when running on RI.
*/
filteredRowSet.moveToInsertRow();
filteredRowSet.updateInt(1, 10);
filteredRowSet.updateString(2, "insert10");
filteredRowSet.insertRow();
filteredRowSet.moveToCurrentRow();
}
示例7: testFilter_Update
import javax.sql.rowset.FilteredRowSet; //导入方法依赖的package包/类
public void testFilter_Update() throws Exception {
FilteredRowSet filteredRowSet = newFilterRowSet();
rs = st.executeQuery("SELECT * FROM USER_INFO");
filteredRowSet.populate(rs);
Predicate range = new RangeOne();
filteredRowSet.setFilter(range);
/*
* Update the third row. Filter has no effect here.
*/
assertTrue(filteredRowSet.last());
assertEquals("test4", filteredRowSet.getString(2));
filteredRowSet.updateString(2, "update4");
filteredRowSet.updateRow();
assertEquals("update4", filteredRowSet.getString(2));
// the updated row becomes not visible through filter
assertTrue(filteredRowSet.last());
assertEquals("test3", filteredRowSet.getString(2));
// commit to database
filteredRowSet.acceptChanges(conn);
rs = st
.executeQuery("SELECT COUNT(*) FROM USER_INFO WHERE NAME = 'update4'");
assertTrue(rs.next());
assertEquals(0, rs.getInt(1));
/*
* Remove filter
*/
filteredRowSet.setFilter(null);
assertTrue(filteredRowSet.last());
assertEquals("update4", filteredRowSet.getString(2));
/*
* The forth row isn't updated to database, and it lost it's status
* after acceptChanges().
*/
assertFalse(filteredRowSet.rowUpdated());
}
示例8: testFilter_Delete
import javax.sql.rowset.FilteredRowSet; //导入方法依赖的package包/类
public void testFilter_Delete() throws Exception {
FilteredRowSet filteredRowSet = newFilterRowSet();
rs = st.executeQuery("SELECT * FROM USER_INFO");
filteredRowSet.populate(rs);
/*
* Mark the first row as delete.
*/
assertTrue(filteredRowSet.first());
assertEquals(1, filteredRowSet.getInt(1));
filteredRowSet.deleteRow();
Predicate range = new RangeOne();
filteredRowSet.setFilter(range);
assertTrue(filteredRowSet.first());
assertEquals(2, filteredRowSet.getInt(1));
filteredRowSet.acceptChanges(conn);
rs = st.executeQuery("SELECT COUNT(*) FROM USER_INFO WHERE ID = 1");
assertTrue(rs.next());
assertEquals(1, rs.getInt(1));
/*
* Remove filter
*/
filteredRowSet.setFilter(null);
filteredRowSet.acceptChanges(conn);
rs = st.executeQuery("SELECT COUNT(*) FROM USER_INFO WHERE ID = 1");
assertTrue(rs.next());
assertEquals(1, rs.getInt(1));
/*
* The first row has been deleted from FilteredRowSet. However, it isn't
* deleted from database.
*/
filteredRowSet.setShowDeleted(true);
assertTrue(filteredRowSet.first());
assertEquals(2, filteredRowSet.getInt(1));
}
示例9: testSetFilter
import javax.sql.rowset.FilteredRowSet; //导入方法依赖的package包/类
public void testSetFilter() throws Exception {
FilteredRowSet filteredRowSet = newFilterRowSet();
rs = st.executeQuery("SELECT * FROM USER_INFO");
filteredRowSet.populate(rs);
/*
* Set Filter: RangeOne
*/
Predicate range = new RangeOne();
filteredRowSet.setFilter(range);
filteredRowSet.beforeFirst();
int index = 0;
while (filteredRowSet.next()) {
index++;
assertTrue(filteredRowSet.getString(2).indexOf("test") != -1);
}
assertEquals(3, index);
assertSame(range, filteredRowSet.getFilter());
/*
* Set another Filter: RangeTwo
*/
range = new RangeTwo();
filteredRowSet.setFilter(range);
filteredRowSet.beforeFirst();
index = 0;
boolean isSecondRowFiltered = true;
while (filteredRowSet.next()) {
index++;
if ("test2".equals(filteredRowSet.getString(2))) {
isSecondRowFiltered = false;
}
}
assertEquals(3, index);
assertTrue(isSecondRowFiltered);
assertSame(range, filteredRowSet.getFilter());
/*
* Remove Filter
*/
filteredRowSet.setFilter(null);
filteredRowSet.beforeFirst();
index = 0;
while (filteredRowSet.next()) {
index++;
assertEquals(index, filteredRowSet.getInt(1));
}
assertEquals(4, index);
assertNull(filteredRowSet.getFilter());
}
示例10: testSetFilterOnFilteredRow
import javax.sql.rowset.FilteredRowSet; //导入方法依赖的package包/类
public void testSetFilterOnFilteredRow() throws Exception {
FilteredRowSet filteredRowSet = newFilterRowSet();
rs = st.executeQuery("SELECT * FROM USER_INFO");
filteredRowSet.populate(rs);
filteredRowSet.next();
assertEquals(1, filteredRowSet.getRow());
Predicate range = new RangeOne();
filteredRowSet.setFilter(range);
// not filtered
assertEquals(1, filteredRowSet.getRow());
assertEquals("hermit", filteredRowSet.getString(2));
filteredRowSet.updateString(2, "update");
assertEquals("update", filteredRowSet.getString(2));
filteredRowSet.next();
assertEquals(2, filteredRowSet.getRow());
assertEquals("test", filteredRowSet.getString(2));
filteredRowSet.previous();
assertTrue(filteredRowSet.isBeforeFirst());
try {
filteredRowSet.getString(2);
fail("should should SQLException");
} catch (SQLException e) {
// expected, Not a valid cursor
}
filteredRowSet.setFilter(null);
assertTrue(filteredRowSet.isBeforeFirst());
assertTrue(filteredRowSet.next());
assertEquals("update", filteredRowSet.getString(2));
filteredRowSet.setFilter(range);
assertEquals("update", filteredRowSet.getString(2));
filteredRowSet.updateString(2, "testUpdate");
filteredRowSet.next();
assertEquals(2, filteredRowSet.getRow());
assertEquals("test", filteredRowSet.getString(2));
filteredRowSet.previous();
assertEquals(1, filteredRowSet.getRow());
assertEquals("testUpdate", filteredRowSet.getString(2));
}
示例11: testAbsolute
import javax.sql.rowset.FilteredRowSet; //导入方法依赖的package包/类
public void testAbsolute() throws Exception {
FilteredRowSet filteredRowSet = newFilterRowSet();
rs = st.executeQuery("SELECT * FROM USER_INFO");
filteredRowSet.populate(rs);
/*
* When running on RI, filteredRowSet.absolute(1) is false here.
* However, the cursor moves to the first row already.
*/
if ("true".equals(System.getProperty("Testing Harmony"))) {
assertTrue(filteredRowSet.absolute(1));
} else {
assertFalse(filteredRowSet.absolute(1));
}
assertEquals("hermit", filteredRowSet.getString(2));
RangeOne range = new RangeOne();
filteredRowSet.setFilter(range);
/*
* When running on RI, filteredRowSet.absolute(1) is false.
*/
if ("true".equals(System.getProperty("Testing Harmony"))) {
assertTrue(filteredRowSet.absolute(1));
} else {
assertFalse(filteredRowSet.absolute(1));
}
assertEquals("test", filteredRowSet.getString(2));
range.clear();
assertTrue(filteredRowSet.absolute(2));
assertEquals(3, filteredRowSet.getRow());
assertEquals(3, filteredRowSet.getInt(1));
assertEquals(EVALUATE_ROWSET, range.getTag());
assertEquals(3, range.getCount());
range.clear();
assertTrue(filteredRowSet.absolute(2));
assertEquals(3, filteredRowSet.getInt(1));
assertEquals(EVALUATE_ROWSET, range.getTag());
assertEquals(3, range.getCount());
range.clear();
assertTrue(filteredRowSet.absolute(3));
assertEquals(4, filteredRowSet.getInt(1));
assertEquals(EVALUATE_ROWSET, range.getTag());
assertEquals(4, range.getCount());
assertFalse(filteredRowSet.absolute(4));
assertTrue(filteredRowSet.absolute(-2));
assertEquals(3, filteredRowSet.getInt(1));
assertTrue(filteredRowSet.absolute(-3));
assertEquals(2, filteredRowSet.getInt(1));
assertFalse(filteredRowSet.absolute(-4));
assertTrue(filteredRowSet.isBeforeFirst());
}
示例12: testCursorMove
import javax.sql.rowset.FilteredRowSet; //导入方法依赖的package包/类
public void testCursorMove() throws Exception {
insertMoreData(30);
FilteredRowSet filteredRowSet = newFilterRowSet();
rs = st.executeQuery("SELECT * FROM USER_INFO");
filteredRowSet.populate(rs);
RangeThree range = new RangeThree();
filteredRowSet.setFilter(range);
assertTrue(filteredRowSet.first());
assertEquals("hermit", filteredRowSet.getString(2));
/*
* TODO It's really strange. When running on RI, filteredRowSet.first()
* is true. The cursor stays on the first row. However,
* filteredRowSet.absolute(1) is false. But the cursor still stays on
* the first row.
*/
if ("true".equals(System.getProperty("Testing Harmony"))) {
assertTrue(filteredRowSet.absolute(1));
} else {
assertFalse(filteredRowSet.absolute(1));
}
assertEquals("hermit", filteredRowSet.getString(2));
assertTrue(filteredRowSet.relative(1));
assertEquals("test4", filteredRowSet.getString(2));
/*
* First call absolute(2), then call relative(-1), the cursor returns
* the first row.
*/
assertTrue(filteredRowSet.absolute(2));
assertEquals("test4", filteredRowSet.getString(2));
assertTrue(filteredRowSet.relative(-1));
assertEquals("hermit", filteredRowSet.getString(2));
assertTrue(filteredRowSet.last());
assertEquals("test34", filteredRowSet.getString(2));
assertTrue(filteredRowSet.previous());
assertEquals("test32", filteredRowSet.getString(2));
assertTrue(filteredRowSet.relative(-1));
assertEquals("test30", filteredRowSet.getString(2));
assertTrue(filteredRowSet.absolute(5));
assertEquals("test10", filteredRowSet.getString(2));
assertTrue(filteredRowSet.relative(3));
assertEquals("test16", filteredRowSet.getString(2));
assertTrue(filteredRowSet.relative(-3));
assertEquals("test10", filteredRowSet.getString(2));
assertTrue(filteredRowSet.relative(4));
assertEquals("test18", filteredRowSet.getString(2));
assertTrue(filteredRowSet.relative(13));
assertEquals("test34", filteredRowSet.getString(2));
assertFalse(filteredRowSet.next());
assertTrue(filteredRowSet.isAfterLast());
assertTrue(filteredRowSet.absolute(22));
assertEquals("test34", filteredRowSet.getString(2));
assertTrue(filteredRowSet.relative(-21));
assertEquals("hermit", filteredRowSet.getString(2));
assertFalse(filteredRowSet.relative(-1));
assertTrue(filteredRowSet.isBeforeFirst());
}
示例13: testFilter_Insert
import javax.sql.rowset.FilteredRowSet; //导入方法依赖的package包/类
public void testFilter_Insert() throws Exception {
FilteredRowSet filteredRowSet = newFilterRowSet();
rs = st.executeQuery("SELECT * FROM USER_INFO");
filteredRowSet.populate(rs);
Predicate range = new RangeOne();
filteredRowSet.setFilter(range);
/*
* Insert a row. when call updateXXX(), evaluate(Object value, int
* column) is called to check first.
*/
filteredRowSet.afterLast();
filteredRowSet.moveToInsertRow();
filteredRowSet.updateInt(1, 200);
try {
filteredRowSet.updateString("NAME", "test200");
fail("should throw SQLException");
} catch (SQLException e) {
filteredRowSet.updateString("NAME", "insert200");
}
filteredRowSet.insertRow();
filteredRowSet.moveToCurrentRow();
/*
* Although the new row is inserted, it is invalid through
* evaluate(RowSet rs). Therefore, the inserted row is not visible.
*/
filteredRowSet.beforeFirst();
int index = 0;
while (filteredRowSet.next()) {
index++;
assertEquals(index + 1, filteredRowSet.getInt(1));
}
assertEquals(3, index);
/*
* Remove filter. See the inserted row. Then set again, and commit to
* database.
*/
filteredRowSet.setFilter(null);
assertTrue(filteredRowSet.last());
assertEquals(200, filteredRowSet.getInt(1));
assertTrue(filteredRowSet.rowInserted());
filteredRowSet.setFilter(range);
filteredRowSet.acceptChanges(conn);
// check database: the inserted row isn't commited to database
rs = st.executeQuery("SELECT * FROM USER_INFO");
index = 0;
while (rs.next()) {
index++;
assertEquals(index, rs.getInt(1));
}
assertEquals(4, index);
/*
* Remove filter
*/
filteredRowSet.setFilter(null);
filteredRowSet.beforeFirst();
index = 0;
while (filteredRowSet.next()) {
index++;
if (index == 5) {
/*
* Though the new row isn't inserted into database, the inserted
* row lost it's status after acceptChanges().
*/
assertEquals(200, filteredRowSet.getInt(1));
assertFalse(filteredRowSet.rowInserted());
} else {
assertEquals(index, filteredRowSet.getInt(1));
}
}
assertEquals(5, index);
}