Problem

How to manipulate table data by code (server side)


Solution

Dataweb project is based on a RDBMS (HSQLDB or Postgres) but usually you don't use SQL, but the specific classes. The following code shows how to manipulate data in a table on the server side which is the better choice than the client side, because the classes are most efficient:

// Get an active table object
dataweb.datastore.Table tbl=dbSession.openTable("<Package>.<Table>");

// Move cursor to required record
tbl.seek("<Index Name>",new Object[]{<Index parameter1>[,<Index parameter2>]})

// We want to edit some data
tbl.edit();
tbl.setValue("<Column Name>",<Value>);
tbl.update();

// Create new record
tbl.addNew();
tbl.setValue("<Column Name>",<Value>);
....
....
tbl.setValue("<Column Name>",<Value>);
tbl.update();

// Close table object
tbl.close();

Published in Fri, 10 December 2010 16:16