Making the Most of JDBC with WebRowSet

Making the Most of JDBC with WebRowSet

Manipulating ResultSet

You can delete a row by moving cursor to the row position and calling the deleteRow() method on the WebRowSet instance. Similarly, you can update one or more values in a row by moving the cursor to the row position and calling the appropriate update method. The following code example does both.



... ... ...

ResultSet rs = 

  stmt.executeQuery("select * from student ");

WebRowSet wrs = new WebRowSetImpl();

wrs.populate(rs);

wrs.absolute(1); //move to first row

wrs.deleteRow(); //delete current row

wrs.absolute(2); //move to second row

wrs.updateInt(4,20);//update current row

... ... ...

The first four lines of the code snippet are obvious: instantiate the object and populate it with the result set. The next two lines try to delete the first row. The final two lines try to update the value at fourth column of second row to 20. Outputting this WebRowSet object produces the following <data> element.

 <data>

   <deleteRow> 

     <columnValue>200</columnValue> 

     <columnValue>Jack</columnValue> 

     <columnValue>Dakota</columnValue> 

     <columnValue>21</columnValue> 

   </deleteRow> 

   <currentRow> 

     <columnValue>100</columnValue> 

     <columnValue>John</columnValue> 

     <columnValue>Doe</columnValue> 

     <columnValue>26</columnValue> 

     <updateRow>20</updateRow> 

   </currentRow> 

 </data>

This XML snippet shows that the first row is marked for deletion with the <deleteRow> tag. The value in the fourth column position of the second row is marked for update from current value of 26 to a new value of 20.

Committing the Changes

So far I've only manipulated the result. These changes will not be reflected in the underlying database until I commit. The following code, if executes successfully, makes the changes permanent by committing them.

... ... ...

wrs.acceptChanges();

... ... ...

Prev  [1] [2] [3] [4] [5] Next

Close    To Top
  • Prev Article-Java:
  • Next Article-Java:
  • Now: Tutorial for Web and Software Design > Java > JDOnJDBCnSQLJ > Java Content
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Geek Tutorial
     

    Blogging Tutorial

      RSS Tutorial
      Podcasting Tutorial
    Graphic Design Tutorial
      Coreldraw Tutorial
      Illustrator Tutorial
      3D Tutorials
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial/ Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial/ Articles
     

    XML Style

      AJAX Tutorial
      XML Mobile
    Flash Tutorial/ Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial/ Articles
      Linux Tutorial
      Symbian Tutorial
      MacOS Tutorial
    Personal Tech
      Hardware Tutorial
      Software Tutorial
      Online Auction