The MarkLogic XQJ API

Quick Start Conformance Report Compliance Definition Statement Download MarkLogic XQJ API

MarkLogic XQJ API 1.0 Release Candidate 3

Quick Start

  1. Download and install MarkLogic Server.
  2. Create an XDBC Server listening on the port 8003.
  3. Download the MarkLogic XQJ API (marklogic-xqj-api-1.0.0-rc3.zip).
  4. Compile and run the following code.
import javax.xml.xquery.*;
import javax.xml.namespace.QName;
import net.xqj.marklogic.MarkLogicXQDataSource;

public class QuickStart
{
  public static void main(String[] args) throws XQException
  {
    XQDataSource xqs = new MarkLogicXQDataSource();
    xqs.setProperty("serverName", "localhost");
    xqs.setProperty("port", "8003");

    // Change USERNAME and PASSWORD values
    XQConnection conn = xqs.getConnection("USERNAME", "PASSWORD");

    XQPreparedExpression xqpe =
    conn.prepareExpression("declare variable $x as xs:string external; $x");

    xqpe.bindString(new QName("x"), "Hello World!", null);

    XQResultSequence rs = xqpe.executeQuery();

    while(rs.next())
      System.out.println(rs.getItemAsString(null));

    conn.close();
  }
}