Difference between revisions of "Documentation/DevGuide/Database/Modifiable Result Sets"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (1 revision(s))
m
Line 10: Line 10:
  
 
The following code fragment creates a modifiable <code>XResultSet</code> object <code>rs</code>. Note that the code also makes <code>rs</code> scrollable. A modifiable <code>ResultSet</code> object does not have to be scrollable, but when changes are made to a result set, the user may want to move around in it. With a scrollable result set, there is the ability to move to particular rows that you can work with. If the type is <code>SCROLL_SENSITIVE</code>, the new value in a row can be obtained after it has changed without refreshing the whole result set.
 
The following code fragment creates a modifiable <code>XResultSet</code> object <code>rs</code>. Note that the code also makes <code>rs</code> scrollable. A modifiable <code>ResultSet</code> object does not have to be scrollable, but when changes are made to a result set, the user may want to move around in it. With a scrollable result set, there is the ability to move to particular rows that you can work with. If the type is <code>SCROLL_SENSITIVE</code>, the new value in a row can be obtained after it has changed without refreshing the whole result set.
 
+
<source lang="java">
 
   XStatement stmt = con.createStatement();
 
   XStatement stmt = con.createStatement();
 
    
 
    
Line 19: Line 19:
 
   XResultSet rs = stmt.executeQuery("SELECT NAME, PRICE FROM SALES");
 
   XResultSet rs = stmt.executeQuery("SELECT NAME, PRICE FROM SALES");
 
   XRow row = (XRow)UnoRuntime.queryInterface(XRow.class, rs);
 
   XRow row = (XRow)UnoRuntime.queryInterface(XRow.class, rs);
 
+
</source>
 
The <code>ResultSet</code> object rs may look similar to this:
 
The <code>ResultSet</code> object rs may look similar to this:
  

Revision as of 15:30, 31 May 2008



Another feature of SDBC is the ability to update rows in a result set using methods in the programming language, rather than sending an SQL command. Before doing this, a modifiable result set must be created. To create a modifiable result set, supply the ResultSetConcurrency constant UPDATABLE to the Statement property ResultSetConcurrency, so that the Statement object creates an modifiable ResultSet object each time it executes a query.

The following code fragment creates a modifiable XResultSet object rs. Note that the code also makes rs scrollable. A modifiable ResultSet object does not have to be scrollable, but when changes are made to a result set, the user may want to move around in it. With a scrollable result set, there is the ability to move to particular rows that you can work with. If the type is SCROLL_SENSITIVE, the new value in a row can be obtained after it has changed without refreshing the whole result set.

  XStatement stmt = con.createStatement();
 
  XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, stmt);
  xProp.setPropertyValue("ResultSetType", new java.lang.Integer(ResultSetType.SCROLL_INSENSITIVE));
  xProp.setPropertyValue("ResultSetConcurrency", new java.lang.Integer(ResultSetConcurrency.UPDATABLE));
 
  XResultSet rs = stmt.executeQuery("SELECT NAME, PRICE FROM SALES");
  XRow row = (XRow)UnoRuntime.queryInterface(XRow.class, rs);

The ResultSet object rs may look similar to this:

NAME PRICE
Linux $30.00
Beef $15.78
Orange juice $1.50

The methods can now be used in the com.sun.star.sdbc.XRowUpdate interface of the result set to insert a new row into rs, delete an existing row from rs, or modify a column value in rs.

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools