当前位置: 首页>>代码示例>>Java>>正文


Java FilteredRowSet.updateString方法代码示例

本文整理汇总了Java中javax.sql.rowset.FilteredRowSet.updateString方法的典型用法代码示例。如果您正苦于以下问题:Java FilteredRowSet.updateString方法的具体用法?Java FilteredRowSet.updateString怎么用?Java FilteredRowSet.updateString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.sql.rowset.FilteredRowSet的用法示例。


在下文中一共展示了FilteredRowSet.updateString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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();
}
 
开发者ID:shannah,项目名称:cn1,代码行数:16,代码来源:FilteredRowSetTest.java

示例2: 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());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:40,代码来源:FilteredRowSetTest.java

示例3: 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));

}
 
开发者ID:shannah,项目名称:cn1,代码行数:52,代码来源:FilteredRowSetTest.java

示例4: 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);
}
 
开发者ID:shannah,项目名称:cn1,代码行数:77,代码来源:FilteredRowSetTest.java


注:本文中的javax.sql.rowset.FilteredRowSet.updateString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。