ResultSet cancelRowUpdates Example
ResultSet class cancelRowUpdates example. This example shows you how to use cancelRowUpdates method.
ResultSet class cancelRowUpdates example. void cancelRowUpdates() throws SQLException Cancels the updates made to the current row in this ResultSet object. This method may be called after calling an updater method(s) and before calling the method updateRow to roll back the updates made to a row. If no updates have been made or updateRow has already been called, this method has no effect.
Here is the code
/*
* @ # CancelRowUpdates.java
* A class repersenting use to cancelRowUpdates method
* of ResultSet Interface in java.sql package
* version 23 June 2008
* author Rose India
*/
import java.sql.*;
public class CancelRowUpdates {
public static void main(String[] args) throws Exception {
Connection con = null;
Statement st = null;
ResultSet rs = null;
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://192.168.10.59:3306/";
String db = "Student";
Class.forName(driver);
con = DriverManager.getConnection(url + db, "root", "root");
try {
String sql = "Select * from stu_info";
st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
rs = st.executeQuery(sql);
// Move cursor to the row to update
rs.first();
// Update the value of column col_string on that row
rs.updateString("name", "komal");
rs.cancelRowUpdates();
System.out.println("name " + rs.getString("name"));
} catch (Exception e) {
System.out.println(e.toString());
}
}
} |
|