Modifiable Result Sets

From Apache OpenOffice Wiki
Jump to: navigation, search

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:

Linux $30.00
Beef $15.78
Orange juice $1.50

The methods can now be used in the 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
In other languages