Updating Data in Relational Databases


You can execute updating expressions using either XQExpression or XQPreparedExpression objects. The result of an updating query is always an empty sequence.

The following example executes an updating expression in XQJ using an XQExpression object. The updating expression inserts data into the holdings database table.

// import the XQJ classes 
import javax.xml.xquery.*; 
import com.ddtek.xquery.xqj.DDXQDataSource; 
 
// establish a connection to a relational data source 
// specify the URL and the user ID and password 
DDXQDataSource ds = new DDXQDataSource(); 
ds.setJdbcUrl("jdbc:xquery:sqlserver://server1:1433;databaseName=stocks"); 
XQConnection conn = ds.getConnection("myuserid", "mypswd"); 
// create an expression object that is used to execute a query 
XQExpression xqExpression = conn.createExpression(); 
 
// the query 
String es = "ddtek:sql-insert('holdings'," + 
             "'userid','Minollo','stockticker','TIVO','shares',200)"; 
 
// execute the query 
XQResultSequence result = xqExpression.executeQuery(es); 
 
// free all resources 
result.close(); 
xqExpression.close(); 
conn.close(); 

Other examples can be found in the RDBMSUpdate example.

See Updating Relational Data for more information about updating data in relational databases.