JDBC 3.0 rowset, similar to the ADO Programming Method in Windows

Source: Internet
Author: User

JDBC is slow enough. When it reaches 3.0, A rowset can be similar to the concept of ADO in windows, but it still cannot reach the level of ado.net. Thanks to the competition for ORM in Java, C #'s objectspace can continue to be awesome.

Compared with resultset, rowset does not need to maintain connecton. It is more important to be able to directly assign values to row for insert and update in a way similar to ADO programming, rather than writing SQL statements. This mode is often seen in Windows programming. Especially when ado.net is used, Orm can only be regarded as a icing on the cake ....

In the sample code of Oracle, rowset02.java provides a complete demo of the ADO mode of rowset.
The simplified code is as follows:


public class RowSet02 {
  public static void main (String []args)
  {
   try
    {
      OracleCachedRowSet crowset = new OracleCachedRowSet ();
    
      crowset.setUrl (java:oracle:oci8:@);
      crowset.setUsername ("hr");
      crowset.setPassword ("hr");
    
      /*Select*/
      crowset.setCommand ("SELECT seatno, tdate, name, class FROM reservation");
      crowset.execute ();

      System.out.println ("Seat no  Travel Date  Name   Class");
      while (crowset.next ())
      {
        printRow (crowset);
      }

      crowset.setReadOnly (false);

      /*Update*/
      crowset.beforeFirst ();
      if (crowset.absolute (2))
      {
        crowset.updateString (4, "Business");
        crowset.updateRow ();
      }

      /*Insert*/    
      crowset.beforeFirst ();
      crowset.moveToInsertRow ();
      crowset.updateInt (1, 107);
      crowset.updateDate (2, new Date (975915381774L));
      crowset.updateString (3, "Pluto");
      crowset.insertRow ();
   
      /*Delete*/
      crowset.beforeFirst ();
      if (crowset.absolute (6))
      {
        crowset.deleteRow ();
      }

     
      crowset.acceptChanges ();
      crowset.close ();

     
    }catch (SQLException ea)
    {
      ea.printStackTrace ();
    }
  }

 
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.