Write a java program which illustrates the concept of updatable ResultSet?
import java.sql.*;
class UpdateResultSet {
public static void main(String[] args) {
try {
Class.forName("Sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("DRIVERS LOADED...");
Connection con = DriverManager.getConnection("jdbc:odbc:oradsn", "scott", "tiger");
System.out.println("CONNECTION ESTABLISHED...");
Statement st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = st.executeQuery("select * from emp1");
rs.next();
rs.updateInt(2, 8000);
rs.updateRow();
System.out.println("1 ROW UPDATED...");
rs.moveToInsertRow();
rs.updateInt(1, 104);
rs.updateInt(2, 2000);
rs.insertRow();
System.out.println("1 ROW INSERTED...");
rs.absolute(2);
rs.deleteRow();
System.out.println("1 ROW DELETED...");
con.close();
} catch (Exception e) {
e.printStackTrace();
}
} // main
} // UpdateResultSet
import java.sql.*;
class UpdateResultSet {
public static void main(String[] args) {
try {
Class.forName("Sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("DRIVERS LOADED...");
Connection con = DriverManager.getConnection("jdbc:odbc:oradsn", "scott", "tiger");
System.out.println("CONNECTION ESTABLISHED...");
Statement st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = st.executeQuery("select * from emp1");
rs.next();
rs.updateInt(2, 8000);
rs.updateRow();
System.out.println("1 ROW UPDATED...");
rs.moveToInsertRow();
rs.updateInt(1, 104);
rs.updateInt(2, 2000);
rs.insertRow();
System.out.println("1 ROW INSERTED...");
rs.absolute(2);
rs.deleteRow();
System.out.println("1 ROW DELETED...");
con.close();
} catch (Exception e) {
e.printStackTrace();
}
} // main
} // UpdateResultSet