Introduction to DataDirect XQuery™ and XQJ

This Java example (click here to open the Java code) shows how simple it is to setup and execute an XQuery using DataDirect XQuery™ and its XQJ interface. The example references a 201 ACORD XML message used in Updating a Relational Database, but it can easily be modified/parameterized to execute other examples described in XQuery Operation Examples for an ACORD Insurance Application.

As you can see the core of the Java code is straightforward:

  public void run() throws Exception {
    // configure datasource
    DDXQDataSource ds = new DDXQDataSource();
    ds.setBaseUri(Acord201.queryBaseDir);
    ds.setJdbcUrl(connectionUrl);

    // connect
    XQConnection c = ds.getConnection();
    
    // create expression
    XQExpression expr = c.createExpression();

    // bind input document
    String uri = new File(Acord201.queryBaseDir + Acord201.inputDoc).toURI().toString();
    SAXSource request = Acord201.getSAXSource(uri);
    expr.bindDocument(new QName("request"), request);

    // execute XQuery
    XQSequence reply = expr.executeQuery(new FileInputStream(new File(Acord201.queryBaseDir + Acord201.inputQuery)));

    // dump reply to stdout
    Acord201.dumpSequence(reply);
    expr.close();

    c.close();
  }

The example code dumps the XQuery result to stdout, but that can be changed to suit your needs (creating a file, streaming the result to another XQuery processing, creating an XML DOM representation of the result, or feeding the result to an XSL-FO processor, for example).

What's Next?

Go to Using DataDirect XQuery™ and XQJ with EJB to learn how to use DataDirect XQuery™ and XQJ to create a Message Enterprise Java Bean.

DataDirect XQuery FAQ

This informative DataDirect XQuery® FAQ answers frequently-asked questions about DataDirect XQuery® , including questions about performance, scalability, use-cases, resources, and more.

If you're more of a hands-on learner, then download a free copy and start exploring DataDirect XQuery® today!

New Case Study

Gevity produces sales proposals in real time using DataDirect XQuery® . See how Gevity uses DataDirect XQuery® to combine Web service data from SalesForce.com with relational data in Oracle in a pricing engine for HR management.