本文整理匯總了Java中java.sql.ResultSet.deleteRow方法的典型用法代碼示例。如果您正苦於以下問題:Java ResultSet.deleteRow方法的具體用法?Java ResultSet.deleteRow怎麽用?Java ResultSet.deleteRow使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.sql.ResultSet
的用法示例。
在下文中一共展示了ResultSet.deleteRow方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testDeletable2
import java.sql.ResultSet; //導入方法依賴的package包/類
public void testDeletable2() {
try {
Connection c =
DriverManager.getConnection("jdbc:hsqldb:mem:mytestdb", "SA",
"");
String createSQL =
"create table test (num INTEGER PRIMARY KEY, str VARCHAR(25))";
Statement createStmt = c.createStatement();
createStmt.execute(createSQL);
createStmt.close();
String ins = "insert into test (num,str) values (?,?)";
PreparedStatement pStmt = c.prepareStatement(ins);
for (int i = 0; i < 100; i++) {
pStmt.setInt(1, i);
pStmt.setString(2, "String" + i);
pStmt.execute();
}
// there should now be 100 rows in the table
String select = "SELECT * FROM test";
PreparedStatement stmt = c.prepareStatement(select,
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery();
rs.beforeFirst();
while (rs.next()) {
int num = rs.getInt("num");
if ((num % 7) == 0) {
System.out.println("Deleting row:" + num);
rs.deleteRow();
}
}
Statement dropStmt = c.createStatement();
dropStmt.execute("drop table test;");
dropStmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
示例2: testQuery
import java.sql.ResultSet; //導入方法依賴的package包/類
public void testQuery() {
try {
Connection c = newConnection();
Statement st = c.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String s =
"CREATE TABLE T (I INTEGER, C CHARACTER(10), B BIT(4) DEFAULT B'')";
st.execute(s);
s = "INSERT INTO T VALUES(?,?, DEFAULT)";
PreparedStatement ps = c.prepareStatement(s);
for (int i = 1; i <= 20; i++) {
ps.setInt(1, i);
ps.setString(2, "TEST " + i);
ps.execute();
}
c.setAutoCommit(false);
s = "SELECT * FROM T";
ResultSet rs = st.executeQuery(s);
rs.absolute(10);
rs.updateString(2, "UPDATE10");
rs.updateRow();
rs.absolute(11);
rs.deleteRow();
rs.moveToInsertRow();
rs.updateInt(1, 1011);
rs.updateString(2, "INSERT1011");
rs.updateString(3, "0101");
rs.insertRow();
rs.close();
rs = st.executeQuery(s);
while (rs.next()) {
System.out.println("" + rs.getInt(1) + " "
+ rs.getString(2) + " "
+ rs.getString(3));
}
st.execute("SHUTDOWN");
if (!isNetwork) {
c.close();
}
} catch (Exception e) {
System.out.print(e);
}
}