本文整理汇总了Java中javax.sql.rowset.JdbcRowSet.close方法的典型用法代码示例。如果您正苦于以下问题:Java JdbcRowSet.close方法的具体用法?Java JdbcRowSet.close怎么用?Java JdbcRowSet.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.sql.rowset.JdbcRowSet
的用法示例。
在下文中一共展示了JdbcRowSet.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testExecute_SelectCmd
import javax.sql.rowset.JdbcRowSet; //导入方法依赖的package包/类
public void testExecute_SelectCmd() throws Exception {
JdbcRowSet jrs = newJdbcRowSet();
jrs.setCommand("SELECT * FROM USER_INFO WHERE ID > ?");
jrs.setUrl(DERBY_URL);
jrs.setInt(1, 1);
jrs.execute();
assertEquals(ResultSet.TYPE_SCROLL_INSENSITIVE, jrs.getType());
assertEquals(ResultSet.CONCUR_UPDATABLE, jrs.getConcurrency());
assertTrue(jrs.getAutoCommit());
assertTrue(jrs.first());
assertEquals(2, jrs.getInt(1));
assertTrue(jrs.absolute(2));
assertEquals(3, jrs.getInt(1));
assertTrue(jrs.last());
assertEquals(4, jrs.getInt(1));
assertTrue(jrs.previous());
assertEquals(3, jrs.getInt(1));
assertTrue(jrs.relative(-1));
assertEquals(2, jrs.getInt(1));
jrs.close();
}
示例2: 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));
}
示例3: testDeleteRow
import javax.sql.rowset.JdbcRowSet; //导入方法依赖的package包/类
public void testDeleteRow() throws Exception {
insertMoreData(6);
JdbcRowSet jrs = newJdbcRowSet();
jrs.setCommand("SELECT * FROM USER_INFO");
jrs.setUrl(DERBY_URL);
jrs.execute();
assertTrue(jrs.first());
jrs.deleteRow();
try {
jrs.getInt(1);
fail("should throw SQLException");
} catch (SQLException e) {
// expected
}
jrs.close();
/*
* Check database
*/
rs = st.executeQuery("SELECT COUNT(*) FROM USER_INFO WHERE ID = 1");
assertTrue(rs.next());
assertEquals(0, rs.getInt(1));
}
示例4: testGetStatement
import javax.sql.rowset.JdbcRowSet; //导入方法依赖的package包/类
public void testGetStatement() throws Exception {
JdbcRowSet jrs = newJdbcRowSet();
assertNull(jrs.getStatement());
jrs.setCommand("SELECT * FROM USER_INFO");
jrs.setUrl(DERBY_URL);
jrs.execute();
assertTrue(jrs.getStatement() instanceof PreparedStatement);
jrs.close();
try {
assertNull(jrs.getStatement());
fail("Should throw SQLException");
} catch (SQLException e) {
// expected
}
}
示例5: testGetRowSetWarnings
import javax.sql.rowset.JdbcRowSet; //导入方法依赖的package包/类
public void testGetRowSetWarnings() throws Exception {
JdbcRowSet jrs = newJdbcRowSet();
jrs.setCommand("SELECT * FROM USER_INFO");
jrs.setUrl(DERBY_URL);
jrs.execute();
/*
* TODO not sure when and how will cause RowSetWarning
*/
assertNull(jrs.getRowSetWarnings());
jrs.close();
jrs = newJdbcRowSet();
RowSetWarning warning = jrs.getRowSetWarnings();
super.assertNull(warning);
// TODO Try to produce warnings.
jrs.close();
// Checks for Exception after closing jrs.
assertNull(rs.getWarnings());
assertNull(jrs.getRowSetWarnings());
}
示例6: testCursorMove
import javax.sql.rowset.JdbcRowSet; //导入方法依赖的package包/类
public void testCursorMove() throws Exception {
insertMoreData(6);
JdbcRowSet jrs = newJdbcRowSet();
jrs.setUrl(DERBY_URL);
jrs.setCommand("SELECT * FROM USER_INFO");
jrs.execute();
jrs.beforeFirst();
assertTrue(jrs.isBeforeFirst());
assertTrue(jrs.next());
assertTrue(jrs.first());
assertFalse(jrs.previous());
assertTrue(jrs.isBeforeFirst());
assertTrue(jrs.absolute(1));
assertTrue(jrs.first());
assertEquals(1, jrs.getInt(1));
assertTrue(jrs.relative(3));
assertEquals(4, jrs.getInt(1));
assertTrue(jrs.previous());
assertEquals(3, jrs.getInt(1));
assertTrue(jrs.relative(-2));
assertTrue(jrs.first());
assertTrue(jrs.absolute(10));
assertEquals(10, jrs.getInt(1));
assertTrue(jrs.last());
assertFalse(jrs.next());
assertTrue(jrs.isAfterLast());
assertTrue(jrs.relative(-2));
assertEquals(9, jrs.getInt(1));
jrs.afterLast();
assertTrue(jrs.isAfterLast());
assertTrue(jrs.absolute(-3));
assertEquals(8, jrs.getInt(1));
jrs.close();
}
示例7: testExecute_UpdateCmd
import javax.sql.rowset.JdbcRowSet; //导入方法依赖的package包/类
public void testExecute_UpdateCmd() throws Exception {
JdbcRowSet jrs = newJdbcRowSet();
jrs.setCommand("Update User_INFO set Name= ? Where ID= ? ");
jrs.setUrl(DERBY_URL);
jrs.setString(1, "update");
jrs.setInt(2, 3);
try {
jrs.execute();
fail("should throw SQLException");
} catch (SQLException e) {
// expected
}
jrs.close();
}
示例8: testExecute_DeleteCmd
import javax.sql.rowset.JdbcRowSet; //导入方法依赖的package包/类
public void testExecute_DeleteCmd() throws Exception {
JdbcRowSet jrs = newJdbcRowSet();
jrs.setCommand("DELETE FROM USER_INFO");
jrs.setUrl(DERBY_URL);
try {
jrs.execute();
fail("should throw SQLException");
} catch (SQLException e) {
// expected
}
jrs.close();
}
示例9: testExecute_InsertCmd
import javax.sql.rowset.JdbcRowSet; //导入方法依赖的package包/类
public void testExecute_InsertCmd() throws Exception {
JdbcRowSet jrs = newJdbcRowSet();
jrs.setCommand("insert into USER_INFO(ID,NAME) values (6,'insert6')");
jrs.setUrl(DERBY_URL);
try {
jrs.execute();
fail("should throw SQLException");
} catch (SQLException e) {
// expected
}
jrs.close();
}
示例10: 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));
}
示例11: 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));
}
示例12: 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();
}
示例13: testResult
import javax.sql.rowset.JdbcRowSet; //导入方法依赖的package包/类
public void testResult() throws Exception {
JdbcRowSet jrs = newJdbcRowSet();
assertTrue(jrs instanceof BaseRowSet);
jrs.setCommand("select * from USER_INFO");
jrs.setUrl(DERBY_URL);
// before execute
assertEquals(ResultSet.TYPE_SCROLL_INSENSITIVE, jrs.getType());
assertTrue(jrs.getEscapeProcessing());
assertEquals(Connection.TRANSACTION_READ_COMMITTED, jrs
.getTransactionIsolation());
try {
assertEquals(ResultSet.FETCH_FORWARD, jrs.getFetchDirection());
fail("Should throw NullPointerException");
} catch (NullPointerException e) {
// expected
}
assertEquals(0, jrs.getFetchSize());
assertEquals(0, jrs.getMaxFieldSize());
assertEquals(0, jrs.getMaxRows());
assertEquals(0, jrs.getQueryTimeout());
assertFalse(jrs.getShowDeleted());
assertEquals(DERBY_URL, jrs.getUrl());
assertNull(jrs.getUsername());
assertNull(jrs.getPassword());
jrs.execute();
// after execute
assertEquals(ResultSet.TYPE_SCROLL_INSENSITIVE, jrs.getType());
assertTrue(jrs.getEscapeProcessing());
assertEquals(Connection.TRANSACTION_READ_COMMITTED, jrs
.getTransactionIsolation());
assertEquals(ResultSet.FETCH_FORWARD, jrs.getFetchDirection());
assertEquals(0, jrs.getFetchSize());
assertEquals(0, jrs.getMaxFieldSize());
assertEquals(0, jrs.getMaxRows());
assertEquals(0, jrs.getQueryTimeout());
assertFalse(jrs.getShowDeleted());
assertEquals(DERBY_URL, jrs.getUrl());
assertNull(jrs.getUsername());
assertNull(jrs.getPassword());
assertTrue(jrs.next());
assertEquals(1, jrs.getInt(1));
assertTrue(jrs.absolute(3));
assertTrue(jrs.absolute(1));
assertEquals(ResultSet.TYPE_FORWARD_ONLY, rs.getType());
assertTrue(jrs instanceof BaseRowSet);
jrs.close();
}
示例14: 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));
}
示例15: 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));
}