本文整理汇总了Java中javax.sql.rowset.JdbcRowSet.setCommand方法的典型用法代码示例。如果您正苦于以下问题:Java JdbcRowSet.setCommand方法的具体用法?Java JdbcRowSet.setCommand怎么用?Java JdbcRowSet.setCommand使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.sql.rowset.JdbcRowSet
的用法示例。
在下文中一共展示了JdbcRowSet.setCommand方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import javax.sql.rowset.JdbcRowSet; //导入方法依赖的package包/类
public static void main(String[] args) throws SQLException {
try {
JdbcRowSet rowSet = RowSetProvider.newFactory().createJdbcRowSet();
rowSet.setUrl(URL + DB_NAME);
rowSet.setPassword(PASSWORD);
rowSet.setUsername(USER_NAME);
rowSet.setCommand("SELECT * FROM customers WHERE sex = ?");
rowSet.setString(1, "male");
rowSet.execute();
while (rowSet.next()) {
System.out.println(rowSet.getRow() + " " + rowSet.getString(2));
}
} catch (SQLException e) {
e.printStackTrace();
}
}
示例2: 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();
}
示例3: 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));
}
示例4: 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));
}
示例5: 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
}
}
示例6: 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());
}
示例7: 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();
}
示例8: 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();
}
示例9: 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();
}
示例10: 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();
}
示例11: 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();
}
示例12: 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));
}
示例13: 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));
}
示例14: 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();
}
示例15: testGetWhereClause_SingleJdbcRowSet
import javax.sql.rowset.JdbcRowSet; //导入方法依赖的package包/类
/**
* @throws Exception
* @tests java.sql.rowset.joinRowSet#getWhereClause()
*/
public void testGetWhereClause_SingleJdbcRowSet() throws Exception {
String whereClause;
// Creates jdbc rowset.
JdbcRowSet jdbcRs;
jdbcRs = newJdbcRowSet();
jdbcRs.setCommand("SELECT * FROM USER_INFO");
jdbcRs.setUrl(DERBY_URL);
jdbcRs.execute();
jdbcRs.setMatchColumn("ID");
jrs.addRowSet(jdbcRs);
if (System.getProperty("Testing Harmony") == "true") {
whereClause = jrs.getWhereClause();
assertNotNull(whereClause);
} else {
try {
whereClause = jrs.getWhereClause();
fail("Should throw NullPointerException.");
} catch (NullPointerException e) {
// Expected.
}
}
CachedRowSet rowSetInJrs = (CachedRowSet) jrs.getRowSets().iterator()
.next();
rowSetInJrs.setTableName("Table1");
whereClause = jrs.getWhereClause();
assertNotNull(whereClause);
}