I have 2 nodes: person{name, password} and city{name}. and a relationship 
between these two is (person) [:LIVES_IN]->(city). I am trying to generate 
a query to find out who are those people living in city X(where X will be 
coming from a text box).
I am trying to construct this query following a suggestion given from 
stackoverflow.com:

import java.util.ArrayList;import java.util.HashMap;import 
org.neo4j.graphdb.GraphDatabaseService;import org.neo4j.graphdb.Node;import 
org.neo4j.graphdb.RelationshipType;import org.neo4j.graphdb.Transaction;import 
org.neo4j.graphdb.factory.GraphDatabaseFactory;import 
org.neo4j.helpers.collection.IteratorUtil;import java.util.Iterator;import 
java.util.Map;import org.neo4j.cypher.javacompat.ExecutionEngine;import 
org.neo4j.cypher.javacompat.ExecutionResult;
> Node person;Node city;String nodeResulta;
> public static final String DB_PATH="D://db";public static 
> GraphDatabaseService graphDb = null; 
>
> private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {        
>                                  
>         // TODO add your handling code here:
>         try ( Transaction tx = graphDb.beginTx(); ){
>             person= graphDb.createNode();
>             person.setProperty("name", jTextField1.getText());
>             //graphDb.index().forNodes("name").add(name, "name", 
> jTextField1.getText());
>             person.setProperty("password", jPasswordField1.getPassword());
>             graphDb.index().forNodes("person").add(person, 
> "name",jTextField1.getText());
>
>             //password= graphDb.createNode();
>             //password.setProperty("password", jPasswordField1.getPassword());
>             //graphDb.index().forNodes("password").add(password, "password", 
> jPasswordField1.getPassword());
>
>             city= graphDb.createNode();
>             city.setProperty("city", jTextField2.getText());
>             graphDb.index().forNodes("city").add(city, "city", 
> jTextField2.getText());
>              //graphDb.index().forNodes("name").add(name, "password", 
> jPasswordField1.getPassword());
>             //graphDb.index().forNodes("name").add(name, "city", 
> jTextField2.getText());
>
>             person.createRelationshipTo(city, RelTypes.LIVES_IN);
>             tx.success();
>
>         }
>
>
> private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {        
>                                  
>     // TODO add your handling code here:
>     ExecutionEngine engine = new ExecutionEngine( graphDb );
>     ExecutionResult result;
>
>     try ( Transaction ignored = graphDb.beginTx() )
>     {
>         
>         Map<String,Object> params=new HashMap<String,Object>();
>         params.put("city",jTextField2.getText());
>         result=engine.execute("MATCH (city: city {city: { city } } 
> )<-[:LIVES_IN]-(person) RETURN person",params);
>         
>         Iterator<Node> n_column = result.columnAs( "n" );
>         for ( Node node : IteratorUtil.asIterable( n_column ) )
>         {
>             
>             nodeResulta=node.getProperty( "name" )+"\n";
>             
>         }
>         // END SNIPPET: items
>     }
>     //for(String s:nodeResult1 )
>     
>     jTextArea1.setText(nodeResulta);
>           }
>
>
But this query does not give any result as well as any exception.

Is my query formation right? Can any one tell me how can I resolve this?

Thank You

-- 
You received this message because you are subscribed to the Google Groups 
"Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to