0

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.

Ian Roberts
  • 120,891
  • 16
  • 170
  • 183
user3325719
  • 75
  • 4
  • 14

1 Answers1

1

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.
Ian Roberts
  • 120,891
  • 16
  • 170
  • 183
  • I am sorry I don't understand , I already have a whitespace between them .I don´t see the difference between your answer and what I already have .thanks . – user3325719 Apr 10 '14 at 17:46
  • @user3325719 you need to add space _within_ one or other of the string literals either side of the `+` - currently it's `"foo" + "bar" => "foobar"` whereas you need `"foo " + "bar" => "foo bar"`. – Ian Roberts Apr 10 '14 at 17:52