1600 PMP mock questions 1400 CAPM mock questions 800 SCJP 6 mock questions 600 OCAJP 7 mock questions 590 OCPJP 7 mock questions 556 SCWCD 5 mock questions 500 OCEJWCD 6 mock questions pdfDownload (java,struts, hibernet etc)

JDBC Tutorials

Q. What are Scrollable and Updateable ResultSets ?

We can fetch ResultSet data randomly and even update it witout any update queries.
On create statement we have to do :
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);

Example :
public class TestDB {
public static void main(String[] args) {
try {

/** Loading the driver*/

Class.forName("com.mysql.jdbc.Driver");

/** Getting Connection*/
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","test","test");

/** Creating Statement*/

Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
/** Getting ResultSet*/
ResultSet rs=stmt.executeQuery("select * from emp");

while(rs.next()) {
System.out.print("Id is " + rs.getInt("id"));

System.out.println(" Name is "+rs.getString("name"));
}

rs.absolute(1);
rs.updateString(2,"Ram");
rs.updateRow(); // update without calling update query
rs.beforeFirst();
System.out.println("After Updation");



while(rs.next()) {

System.out.print("Id is " + rs.getInt("id"));
System.out.println(" Emp Name is "+rs.getString("name"));

}



/** Closing the Connection*/
stmt.close();
con.close();

} catch (Exception e) {

e.printStackTrace();
}
     }
}



Output:-



Id is 1 Emp Name is das
Id is 2 Emp Name is raj
After Updation

Id is 1 Emp Name is Ram
Id is 2 Emp Name is raj

Reviews and Comments


PMP, CAPM, PMI is a registered certification mark of the Project Management Institute, Inc

Copyright © www.techfaq360.com 2016


About US | Contact US | Privacy Policy | Terms and Conditions  | Website disclaimer  | Cancellation and Refund Policy  | Shipping & Delivery Policy