Java: pass parameters to cypher query

653 views
Skip to first unread message

Tomas Teicher

unread,
Apr 20, 2012, 6:06:39 AM4/20/12
to ne...@googlegroups.com
 I would like to pass parameters to cypher query. I have such a code.

Map<String, Object> params = new HashMap<String, Object>();
        params.put("@par1", "some title");
        params.put("@nid", 3);
        ExecutionResult result = db.engine.execute("START n = node(@nid) with n set n.title = '@par1' RETURN n", params);

I got exception: Exception in thread "main" expected node id, or *
"START n = node(@nid) with n set n.title = '@par1' RETURN n"

 But this doesn't work for me. 
How can I pass parameters to this query?

thanks
Tomas

Tomas Teicher

unread,
Apr 20, 2012, 6:07:21 AM4/20/12
to ne...@googlegroups.com
I am using new version of Cypher (1.8)

Dňa piatok, 20. apríla 2012 12:06:39 UTC+2 Tomas Teicher napísal(-a):

Michael Hunger

unread,
Apr 20, 2012, 6:55:10 AM4/20/12
to ne...@googlegroups.com
Parameters are enclosed in curly brackets. No need for @ prefix.

like 

START n = node({nid}) with n set n.title = {par1} RETURN n

see: http://docs.neo4j.org/chunked/milestone/cypher-parameters.html

Michael

Tomáš Teicher

unread,
Apr 21, 2012, 2:52:08 AM4/21/12
to ne...@googlegroups.com
thank you,
what if I want to have property name as parameter, too?

I have tried

START n = node({nid}) with n set n.{title} = {par1} RETURN n

When creating new node, I can use special Java Map object for key - value properties.
Then I can use cypher syntax:
"create node a = {props}"

Is there any alternative for SET syntax? I have tried
����� "START n = node({id}) with n set n.{props}";
but it doesn't work for me.


Tomas



Dňa 20. 4. 2012 12:55, Michael Hunger� wrote / nap�sal(a):
Parameters are enclosed in curly brackets. No need for @ prefix.

like�

START n = node({nid}) with n set n.title = {par1} RETURN n

Michael Hunger

unread,
Apr 21, 2012, 4:53:25 AM4/21/12
to ne...@googlegroups.com
Hi,

it doesn't work yet but I think a syntax like

set n = {param}

will do in the future.

Michael

Am 21.04.2012 um 08:52 schrieb Tomáš Teicher:

thank you,
what if I want to have property name as parameter, too?

I have tried

START n = node({nid}) with n set n.{title} = {par1} RETURN n

When creating new node, I can use special Java Map object for key - value properties.
Then I can use cypher syntax:
"create node a = {props}"

Is there any alternative for SET syntax? I have tried
      "START n = node({id}) with n set n.{props}";
but it doesn't work for me.


Tomas


Dňa 20. 4. 2012 12:55, Michael Hunger  wrote / napísal(a):
Parameters are enclosed in curly brackets. No need for @ prefix.

like 

START n = node({nid}) with n set n.title = {par1} RETURN n

Reply all
Reply to author
Forward
0 new messages