Follow along with an example to learn how to execute an updating expression in XQJ using an XQExpression object.
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 com.ddtek.xquery3.*;
import com.ddtek.xquery3.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();