本文整理汇总了Java中javax.sql.rowset.JdbcRowSet.moveToInsertRow方法的典型用法代码示例。如果您正苦于以下问题:Java JdbcRowSet.moveToInsertRow方法的具体用法?Java JdbcRowSet.moveToInsertRow怎么用?Java JdbcRowSet.moveToInsertRow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.sql.rowset.JdbcRowSet
的用法示例。
在下文中一共展示了JdbcRowSet.moveToInsertRow方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCancelRowUpdates
import javax.sql.rowset.JdbcRowSet; //导入方法依赖的package包/类
public void testCancelRowUpdates() throws Exception {
JdbcRowSet jrs = newJdbcRowSet();
jrs.setCommand("SELECT * FROM USER_INFO");
jrs.setUrl(DERBY_URL);
jrs.execute();
jrs.moveToInsertRow();
try {
jrs.cancelRowUpdates();
fail("should throw SQLException");
} catch (SQLException e) {
// expected
}
jrs.moveToCurrentRow();
assertTrue(jrs.absolute(3));
jrs.updateString(2, "update3");
jrs.updateRow();
assertTrue(jrs.rowUpdated());
assertEquals("update3", jrs.getString(2));
jrs.cancelRowUpdates();
assertEquals("update3", jrs.getString(2));
assertTrue(jrs.next());
assertEquals(4, jrs.getInt(1));
jrs.updateString(2, "update4");
assertFalse(jrs.rowUpdated());
assertEquals("update4", jrs.getString(2));
jrs.cancelRowUpdates();
assertEquals("test4", jrs.getString(2));
jrs.close();
/*
* Check database
*/
rs = st.executeQuery("SELECT * FROM USER_INFO WHERE ID = 3");
assertTrue(rs.next());
assertEquals("update3", rs.getString(2));
}
示例2: testInsertRow_Single
import javax.sql.rowset.JdbcRowSet; //导入方法依赖的package包/类
public void testInsertRow_Single() throws Exception {
/*
* In JdbcRowSet, the inserted row is the last row. The behavior is the
* same as ResultSet.
*/
JdbcRowSet jrs = newJdbcRowSet();
jrs.setCommand("SELECT * FROM USER_INFO");
jrs.setUrl(DERBY_URL);
jrs.execute();
jrs.moveToInsertRow();
jrs.updateInt(1, 5);
jrs.updateString(2, "insert5");
jrs.insertRow();
jrs.moveToCurrentRow();
// check the inserted row
assertTrue(jrs.absolute(5));
/*
* If uncommenting the following line, then the inserted row which ID is
* 6 would be invisible to JdbcRowSet.
*/
// assertTrue(jrs.isLast());
assertEquals(5, jrs.getInt(1));
jrs.moveToInsertRow();
jrs.updateInt(1, 6);
jrs.updateString(2, "insert6");
jrs.insertRow();
jrs.moveToCurrentRow();
assertTrue(jrs.last());
assertEquals(6, jrs.getInt(1));
assertTrue(jrs.previous());
assertEquals(5, jrs.getInt(1));
jrs.close();
// check db
rs = st
.executeQuery("SELECT COUNT(*) FROM USER_INFO WHERE NAME = 'insert5' OR NAME = 'insert6'");
assertTrue(rs.next());
assertEquals(2, rs.getInt(1));
}
示例3: testInsertRow_Multi
import javax.sql.rowset.JdbcRowSet; //导入方法依赖的package包/类
public void testInsertRow_Multi() throws Exception {
JdbcRowSet jrs = newJdbcRowSet();
jrs.setCommand("SELECT * FROM USER_INFO");
jrs.setUrl(DERBY_URL);
jrs.execute();
jrs.moveToInsertRow();
jrs.updateInt(1, 5);
jrs.updateString(2, "insert5");
jrs.insertRow();
jrs.updateInt(1, 6);
jrs.updateString(2, "insert6");
jrs.insertRow();
jrs.updateInt(1, 7);
jrs.updateString(2, "insert7");
jrs.insertRow();
jrs.moveToCurrentRow();
int index = 0;
jrs.beforeFirst();
while (jrs.next()) {
index++;
assertEquals(index, jrs.getInt(1));
}
assertEquals(7, index);
jrs.close();
/*
* Check database
*/
rs = st
.executeQuery("SELECT COUNT(*) FROM USER_INFO WHERE NAME LIKE 'insert%'");
assertTrue(rs.next());
assertEquals(3, rs.getInt(1));
/*
* Change another way to insert multiple rows
*/
jrs = newJdbcRowSet();
jrs.setCommand("SELECT * FROM USER_INFO");
jrs.setUrl(DERBY_URL);
jrs.execute();
assertTrue(jrs.absolute(7));
jrs.moveToInsertRow();
jrs.updateInt(1, 8);
jrs.updateString(2, "insert8");
jrs.insertRow();
jrs.moveToInsertRow();
jrs.updateInt(1, 9);
jrs.updateString(2, "insert9");
jrs.insertRow();
jrs.moveToInsertRow();
jrs.updateInt(1, 10);
jrs.updateString(2, "insert10");
jrs.insertRow();
jrs.moveToCurrentRow();
/*
* Check JdbcRowSet
*/
assertEquals(7, jrs.getInt(1));
index = 7;
while (jrs.next()) {
index++;
assertEquals(index, jrs.getInt(1));
}
assertEquals(10, index);
jrs.close();
/*
* Check database
*/
rs = st.executeQuery("SELECT COUNT(*) FROM USER_INFO WHERE ID > 7");
assertTrue(rs.next());
assertEquals(3, rs.getInt(1));
}