user3325719
user3325719

Reputation: 75

Invalid XQuery syntax, syntax does not pass static validation

i am getting this error when i am trying to do a query with xqj.

Exception in thread "main" javax.xml.xquery.XQException:
  XQJQS001 - Invalid XQuery syntax, syntax does not pass static validation.
  Root Cause:
  XQueryParseException: Encountered "$" at line 1, column 36.
Was expecting one of:
    "=" ...
    "order" ...

public static void Consultar(XQConnection connexio) throws XQException { Scanner sc = new Scanner(System.in);

    System.out.println(">>>>Please select a mminim stock :)");

    int selec = sc.nextInt();

    String squery = "for $prod  in /productos/produc"
            + "for $zone in $prod/cod_zona"
            + "let $stock :=$prod/stock_minimo"
            + "let $deno :=$prod/denominacion"
            + "let $codi_prod :=$prod/cod_prod"
            + "let $cod:=/zonas/zona[cod_zona = $zone]/cod_zona"
            + "let $nomzona:=/zonas/zona[cod_zona = $zone]/nombre"
            + "let $direc:=/zonas/zona[cod_zona = $zone]/director"
            + "where $prod/$stock < " + selec + ""
            + "return concat('Denominacio:',$deno,'&#xa;' ,"
            + "'Codi producte:',$codi_prod,'&#xa;' ,"
            + "'Stock mínim:',$stock,'&#xa;' ,"
            + "'Codi zona:',$cod,'&#xa;' ,"
            + "  'Nom zona:',$nomzona),'&#xa;'";

    XQPreparedExpression consulta = connexio.prepareExpression(squery);

    XQResultSequence resultat = consulta.executeQuery();

    while (resultat.next()) {
        System.out.println(resultat.getItemAsString(null));
        System.out
                .println("...................................................................");
    }

    connexio.close();

}

Same help .thanks.

Upvotes: 0

Views: 720

Answers (1)

Ian Roberts
Ian Roberts

Reputation: 122414

The string concatenation expression

  "for $prod  in /productos/produc"
+ "for $zone in $prod/cod_zona"

will produce the string

for $prod  in /productos/producfor $zone in $prod/cod_zona

You need to add some kind of whitespace between produc and for, within one of the string literals either side of the +, e.g.:

String squery = "for $prod  in /productos/produc "
            + "for $zone in $prod/cod_zona "
            + "let $stock :=$prod/stock_minimo "
            + "let $deno :=$prod/denominacion "
            // etc etc.

Upvotes: 1

Related Questions