本文整理汇总了Java中javax.sql.rowset.JdbcRowSet.updateRow方法的典型用法代码示例。如果您正苦于以下问题:Java JdbcRowSet.updateRow方法的具体用法?Java JdbcRowSet.updateRow怎么用?Java JdbcRowSet.updateRow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.sql.rowset.JdbcRowSet
的用法示例。
在下文中一共展示了JdbcRowSet.updateRow方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testUpdateRow_Normal
import javax.sql.rowset.JdbcRowSet; //导入方法依赖的package包/类
public void testUpdateRow_Normal() throws Exception {
JdbcRowSet jrs = newJdbcRowSet();
jrs.setCommand("SELECT * FROM USER_INFO");
jrs.setUrl(DERBY_URL);
jrs.execute();
assertTrue(jrs.absolute(3));
assertEquals(3, jrs.getInt(1));
assertEquals("test3", jrs.getString(2));
jrs.updateString(2, "update3");
assertFalse(jrs.rowUpdated());
jrs.updateRow();
assertTrue(jrs.rowUpdated());
assertEquals("update3", jrs.getString(2));
jrs.close();
// check db
rs = st
.executeQuery("SELECT COUNT(*) FROM USER_INFO WHERE NAME = 'update3'");
assertTrue(rs.next());
assertEquals(1, rs.getInt(1));
}
示例2: main
import javax.sql.rowset.JdbcRowSet; //导入方法依赖的package包/类
public static void main(String[] args) throws SQLException {
Connection conn = CreateH2Database.createSimpleDatabase("~/test", true, true);
RowSetFactory rowSetFactory = RowSetProvider.newFactory();
JdbcRowSet dataModel = rowSetFactory.createJdbcRowSet();
dataModel.setUrl(conn.getMetaData().getURL());
dataModel.setUsername(conn.getMetaData().getUserName());
dataModel.setPassword("");
dataModel.setCommand("select * from test_table");
dataModel.execute();
// now update the database
dataModel.absolute(1);
dataModel.setString(2, "Hello world 2");
// This throws an exception but according to
// http://docs.oracle.com/javase/tutorial/jdbc/basics/jdbcrowset.html#updating-column-value
// it shouldn't
try {
dataModel.updateRow();
} catch (Exception ex) {
ex.printStackTrace();
}
conn.close();
}
示例3: 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));
}
示例4: testAutoCommit_False
import javax.sql.rowset.JdbcRowSet; //导入方法依赖的package包/类
public void testAutoCommit_False() throws Exception {
JdbcRowSet jrs = newJdbcRowSet();
jrs.setCommand("SELECT * FROM USER_INFO");
jrs.setUrl(DERBY_URL);
jrs.execute();
jrs.setAutoCommit(false);
assertFalse(jrs.getAutoCommit());
assertTrue(jrs.absolute(3));
jrs.updateString(2, "update3");
jrs.updateRow();
jrs.commit();
jrs.rollback();
/*
* TODO why throw NullPointerException after call rollback()?
*/
try {
jrs.absolute(1);
fail("should throw exception");
} catch (NullPointerException e) {
// expected
}
jrs.close();
/*
* Check database
*/
rs = st
.executeQuery("SELECT COUNT(*) FROM USER_INFO WHERE NAME = 'update3'");
assertTrue(rs.next());
assertEquals(1, rs.getInt(1));
}
示例5: testGetRowSets_SingleJdbcRowSet
import javax.sql.rowset.JdbcRowSet; //导入方法依赖的package包/类
/**
* @throws SQLException
* @tests java.sql.rowset.joinRowSet#getRowSets()
*/
public void testGetRowSets_SingleJdbcRowSet() throws Exception {
// Creates jdbc rowset.
JdbcRowSet jdbcRs;
jdbcRs = newJdbcRowSet();
jdbcRs.setCommand("SELECT * FROM USER_INFO");
jdbcRs.setUrl(DERBY_URL);
jdbcRs.execute();
jdbcRs.setMatchColumn(1);
jrs.addRowSet(jdbcRs);
CachedRowSet returnRowset = (CachedRowSet) jrs.getRowSets().iterator()
.next();
assertNotSame(returnRowset, jrs);
jrs.absolute(4);
jrs.updateString(2, "Updated 4");
jrs.updateRow();
jrs.absolute(4);
assertEquals("Updated 4", jrs.getString(2));
// TODO It is Strange. According to spec, the returned rowset should
// maintain
// the update occured in the joinrowset.
returnRowset.absolute(4);
assertEquals("test4", returnRowset.getString(2));
jdbcRs.absolute(3);
jdbcRs.updateString(2, "Updated 3");
jdbcRs.updateRow();
returnRowset.absolute(3);
assertEquals("test3", returnRowset.getString(2));
jdbcRs.close();
}