java - Neo4J in Netbeans: error with Iterator -
i'm trying learn nosql databases , love integrate netbeans, i'm trying make piece of tutorial code run on pc. encountered issue right @ end, i'm hoping can point me in right direction.
package com.mycompany.neo4jdemo; import org.neo4j.cypher.executionengine; import org.neo4j.cypher.executionresult; import org.neo4j.graphdb.graphdatabaseservice; import org.neo4j.graphdb.label; import org.neo4j.graphdb.node; import org.neo4j.graphdb.relationship; import org.neo4j.graphdb.relationshiptype; import org.neo4j.graphdb.resourceiterator; import org.neo4j.graphdb.transaction; import org.neo4j.graphdb.factory.graphdatabasefactory; import org.neo4j.helpers.collection.iteratorutil; import org.neo4j.kernel.impl.util.stringlogger; public class main { public enum nodetype implements label { person, course; } public enum relationtype implements relationshiptype { knows, belongsto; } public static void main(string[] args) { graphdatabasefactory dbfactory = new graphdatabasefactory(); graphdatabaseservice graphdb = dbfactory.newembeddeddatabase("c:/users/mifouche/documents/neo4j/default.graphdb"); //this database link given neo4j, correct link? executionengine engine = new executionengine(graphdb, stringlogger.system); executionresult result; try(transaction tx = graphdb.begintx()) { //clear database engine.execute("match (n) optional match (n)-[r]-() delete n,r"); //create person bob node properties node bobnode = graphdb.createnode(nodetype.person); bobnode.setproperty("pid", 5001); bobnode.setproperty("name", "bob"); bobnode.setproperty("age", 23); //create person alice node properties node alicenode = graphdb.createnode(nodetype.person); alicenode.setproperty("pid", 5002); alicenode.setproperty("name", "alice"); //create person eve node 1 property node evenode = graphdb.createnode(nodetype.person); evenode.setproperty("name", "eve"); //create course node properties node itnode = graphdb.createnode(nodetype.course); itnode.setproperty("id", 1); itnode.setproperty("name", "it beginners"); itnode.setproperty("location", "room 153"); //create course electronics node properties node electronicnode = graphdb.createnode(nodetype.course); electronicnode.setproperty("name", "electronics advanced"); //set relationship between bob , alice bobnode.createrelationshipto(alicenode, relationtype.knows); //set relationship between bob , course relationship bobrelit = bobnode.createrelationshipto(itnode, relationtype.belongsto); bobrelit.setproperty("function", "student"); //set relationship between bob , electronics course relationship bobrelelectronics = bobnode.createrelationshipto(electronicnode, relationtype.belongsto); bobrelelectronics.setproperty("function", "supply teacher"); //set relationship between alice , course relationship alicerelit = alicenode.createrelationshipto(itnode, relationtype.belongsto); alicerelit.setproperty("function", "teacher"); //stamp transaction successful tx.success(); //find person nodes on neo4j database result = engine.execute("match (n:person) return n"); //fill node columns values database (i think) resourceiterator<node> columns = result.columnas("n"); //iterate through values returned for(node node:iteratorutil.asiterable(columns)) { system.out.println(node + ": "+node.getproperty("name")); } } graphdb.shutdown(); } }
the error appears in line >> resourceiterator columns = result.columnas("n"); error give is: type of columnas(string> erroneous. can seen in image: http://s1294.photobucket.com/user/mfoosh/media/netbeansneo4jerror_zpsx2ygasqh.png.html
i changed of code basis tutorial couldn't find solution yet... tutorial can found here: https://www.youtube.com/watch?v=-g-vcszo_3g
(from basis expand knowledge able read in dataset in xml/csv format , create graph database in neo4j, , there try , determine various information bits findings, hints towards can me?)
you have use "scala.collection.iterator" iterating on nodes.
something : -
string query = "match (n) return n"; executionresult result = engine.execute(query); scala.collection.iterator<object> objresult = result.columnas("n"); while(objresult.hasnext()){ node cyphernode = (node)objresult.next(); ....... }
Comments
Post a Comment