The MarkLogic XQJ API

Quick Start Conformance Report Compliance Definition Statement Download MarkLogic XQJ API

MarkLogic XQJ API 1.0

Quick Start

  1. Download and install MarkLogic Server.
  2. Create an XDBC Server listening on the port 8003.
  3. Download the MarkLogic XQJ API (
  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();



If you use MarkLogic 4.2 or earlier and face difficulties with the latest release,
you may wish to use MarkLogic XQJ 1.0.0 RC3 as this is known to work. Support for MarkLogic 4.2 and earlier will end in December 2013.