Coding Basics
- Last Updated: April 14, 2026
- 1 minute read
To use XCC, there are several basic things you need to do in your Java code:
-
Import the needed libraries.
-
Set up the
ContentSourceobject to authenticate against MarkLogic Server. -
Create a new
Sessionobject. -
Add a
Requestto the session object. -
Submit the request and get back a
ResultSequenceobject from MarkLogic Server. -
Do something with the results (print them out, for example).
-
Close the session.
The following are Java code samples that illustrate these basic design patterns:
package com.marklogic.xcc.examples;
import com.marklogic.xcc.ContentSource;
import com.marklogic.xcc.ContentSourceFactory;
import com.marklogic.xcc.Session;
import com.marklogic.xcc.Request;
import com.marklogic.xcc.ResultSequence;
URI uri = new URI("xcc://user:pass@localhost:8000/mycontent");
ContentSource contentSource =
ContentSourceFactory.newContentSource (uri);
Session session = contentSource.newSession();
Request request = session.newAdhocQuery ("\"Hello World\"");
ResultSequence rs = session.submitRequest (request);
System.out.println (rs.asString());
session.close();
Note: Session objects are not thread safe. A Session object should not be used concurrently by multiple threads.