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 ();
}
}
}