be easily cast to Java primitives via XQItemAccessor methods such as getByte() and getFloat(). Also XQuery items and sequences can be serialized to DOM , SAX , StAX and the generic IO and classes. Examples Basic example The following example illustrates creating a connection to an XML Database, submitting an XQuery expression, then processing the results in Java. Once all of the results have been processed, the connection is closed to free up all resources associated with it. // Create a new connection to an XML database XQConnection conn = vendorDataSource.getConnection("myUser", "myPassword"); XQExpression expr = conn.createExpression(); // Create a reusable XQuery Expression object XQResultSequence result = expr.executeQuery( "for $n in fn:collection('catalog')//item " + "return fn:data($n/name)"); // execute an XQuery expression // Process the result sequence iteratively while (result.next()) { // Print the current item in the sequence System.out.println("Product name: " + result.getItemAsString(null)); } // Free all resources created by the connection conn.close(); Binding a value to an external variable The following example illustrates how a Java value can be bound to an external variable in an XQuery expression. Assume that the connection already exists: XQExpression expr = conn.createExpression(); // The XQuery expression to be executed String es = "declare variable $x as xs:integer external;" + " for $n in fn:collection('catalog')//item" + " where $n/price <= $x" + " return fn:data($n/name)"; // Bind a value (21) to an external variable with the QName x expr.bindInt(new QName("x"), 21, null); // Execute the XQuery expression XQResultSequence result = expr.executeQuery(es); // Process the result (sequence) iteratively while (result.next()) { // Process the result ... } Default data type mapping Mapping between Java and XQuery data types is largely flexible, however the XQJ 1.0 specification does have default mapping rules mapping data types when they are not specified by the user. These mapping rules bear great similarities to the mapping rules found in JAXB. The following table illustrates the default mapping rules for when binding Java values to external variables in XQuery expressions. Known implementations Native XML databases The following is a list of Native XML Databases which are known to have XQuery API for Java implementations. MarkLogic eXist BaseX Sedna Oracle XDB Tamino TigerLogic Relational databases DataDirect provide XQJ adapters for relational databases, by translating XQuery code into SQL on the fly, then converting SQL result sets into a format suitable for XQJ to process further. The following is a couple of known implementations.