本文整理汇总了Java中javax.sql.rowset.JdbcRowSet类的典型用法代码示例。如果您正苦于以下问题:Java JdbcRowSet类的具体用法?Java JdbcRowSet怎么用?Java JdbcRowSet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JdbcRowSet类属于javax.sql.rowset包,在下文中一共展示了JdbcRowSet类的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: testSetMatchColumn_Initial
import javax.sql.rowset.JdbcRowSet; //导入依赖的package包/类
public void testSetMatchColumn_Initial() throws Exception {
JdbcRowSet noInitalJrs = noInitalJdbcRowSet();
JdbcRowSet jrs = newJdbcRowSet();
String[] names = { "1", "2", "3" };
jrs.setMatchColumn(names);
names = jrs.getMatchColumnNames();
assertEquals(13, names.length);
assertEquals("1", names[0]);
assertEquals("2", names[1]);
assertEquals("3", names[2]);
try {
jrs.unsetMatchColumn(new String[] { "3", "2", "1" });
fail("Should throw SQLException");
} catch (SQLException e) {
// expected, Columns being unset are not the same as set
}
}
示例8: 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();
}
示例9: main
import javax.sql.rowset.JdbcRowSet; //导入依赖的package包/类
public static void main(String args[])
{
// connect to database books and query database
try (JdbcRowSet rowSet =
RowSetProvider.newFactory().createJdbcRowSet())
{
// specify JdbcRowSet properties
rowSet.setUrl(DATABASE_URL);
rowSet.setUsername(USERNAME);
rowSet.setPassword(PASSWORD);
rowSet.setCommand("SELECT * FROM authors"); // set query
rowSet.execute(); // execute query
// process query results
ResultSetMetaData metaData = rowSet.getMetaData();
int numberOfColumns = metaData.getColumnCount();
System.out.println("Authors Table of Books Database:\n");
// display rowset header
for (int i = 1; i <= numberOfColumns; i++)
System.out.printf("%-8s\t", metaData.getColumnName(i));
System.out.println();
// display each row
while (rowSet.next())
{
for (int i = 1; i <= numberOfColumns; i++)
System.out.printf("%-8s\t", rowSet.getObject(i));
System.out.println();
}
}
catch (SQLException sqlException)
{
sqlException.printStackTrace();
System.exit(1);
}
}
示例10: newJdbcRowSet
import javax.sql.rowset.JdbcRowSet; //导入依赖的package包/类
private JdbcRowSet newJdbcRowSet() throws Exception {
if ("true".equals(System.getProperty("Testing Harmony"))) {
return (JdbcRowSet) Class.forName(
"org.apache.harmony.sql.internal.rowset.JdbcRowSetImpl")
.newInstance();
}
return (JdbcRowSet) Class.forName("com.sun.rowset.JdbcRowSetImpl")
.newInstance();
}
示例11: 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();
}
示例12: 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();
}
示例13: 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();
}
示例14: 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();
}
示例15: 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));
}