Following is the java program which connects to NEO4J . it is not properly conneting executing cypher queries. Your help at the earliest
表示赞赏。
import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; import javax.xml.soap.Node; import org.neo4j.graphdb.PropertyContainer; import org.neo4j.graphdb.Transaction; import org.apache.struts2.interceptor.SessionAware; import org.neo4j.cypher.CypherParser; import org.neo4j.cypher.ExecutionEngine; import org.neo4j.cypher.javacompat.ExecutionResult; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.factory.GraphDatabaseFactory; import org.neo4j.kernel.EmbeddedGraphDatabase; import com.opensymphony.xwork2.ActionSupport; public class arch extends ActionSupport implements SessionAware { String S; private static final String DB_PATH = "/home/mkgs/Desktop/placement/"; GraphDatabaseService graphDb; private static final long serialVersionUID = 1L; private String pwd; public String getPwd() { return pwd; } public void setPwd(String pwd) { this.pwd = pwd; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } private String username; Map session; public String save() throws Exception { System.out.println("inside save"); System.out.println("username:"+getUsername()); System.out.println("pwd:"+getPwd()); graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH); Transaction transaction = (Transaction) graphDb.beginTx(); try { ExecutionEngine engine = new ExecutionEngine(graphDb, null); ExecutionResult result = (ExecutionResult) engine.execute("START n=node(*) MATCH n-[r]-m RETURN type(r),
计数()ORDER BY计数() 降序&#34); 的System.out.println(结果);
Iterator<Node> columnAs = result.columnAs("n"); while(columnAs.hasNext()) { Node n = (Node)columnAs.next(); for (String key : ((PropertyContainer) n).getPropertyKeys()) { System.out.println("{ " + key + " : " + ((PropertyContainer) n).getProperty(key)+ " } "); } } } finally { ((org.neo4j.graphdb.Transaction) transaction).finish(); } return "l"; } @Override public void setSession(Map arg0) { // TODO Auto-generated method stub } } This is im getting during execution of above code using struts....... Apr 02, 2014 5:53:27 PM org.apache.catalina.core.AprLifecycleListener init INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the
的java.library.path: / usr / lib中/ JVM / JAVA -7-的openjdk-I386 / JRE / LIB / I386 /服务器:/ usr / lib中/ JVM / JAVA -7-的openjdk-I386 / JRE / LIB / I386:/ usr / lib中/ JVM /java-7-openjdk-i386/jre/../lib/i386:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/i386/client:/usr/lib/jvm/java- 7-的openjdk-I386 / JRE / LIB / I386 ::的/ usr /爪哇/包/ LIB / I386:/ usr / lib中/ I386-Linux的GNU / JNI:/ LIB / I386-Linux的GNU:/ usr / lib中/ I386-Linux的GNU:/ usr / lib中/ JNI:/ lib中:/ usr / lib中 2014年4月2日下午5:53:27 org.apache.tomcat.util.digester.SetPropertiesRule开始 警告:[SetPropertiesRule] {服务器/服务/引擎/主机/上下文}设置属性&#39; source&#39;至 &#39; org.eclipse.jst.j2ee.server:placementportal&#39;没找到匹配的 属性。 2014年4月2日下午5:53:27 org.apache.coyote.http11.Http11Protocol init 信息:在http-8080上初始化Coyote HTTP / 1.1 2014年4月2日下午5:53:27 org.apache.catalina.startup.Catalina加载 信息:初始化在645毫秒内处理 2014年4月2日下午5:53:27 org.apache.catalina.core.StandardService开始 信息:开始服务Catalina 2014年4月2日下午5:53:27 org.apache.catalina.core.StandardEngine start 信息:启动Servlet引擎:Apache Tomcat / 6.0.39 2014年4月2日下午5:53:27 org.apache.catalina.loader.WebappClassLoader validateJarFile INFO:validateJarFile(/home/mkgs/workspace/proj/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/placementportal/WEB-INF/lib/servlet-api.jar) - jar没装。请参阅Servlet规范2.3,第9.7.2节。违规类:javax / servlet / Servlet.class 2014年4月2日下午5:53:29 org.apache.coyote.http11.Http11Protocol start 信息:在http-8080上启动Coyote HTTP / 1.1 2014年4月2日下午5:53:29 org.apache.jk.common.ChannelSocket init 信息:JK:ajp13正在收听/0.0.0.0:8009 2014年4月2日下午5:53:29 org.apache.jk.server.JkMain开始 INFO:Jk运行ID = 0时间= 0/29 config = null 2014年4月2日下午5:53:29 org.apache.catalina.startup.Catalina开始 信息:服务器启动于1958年ms
答案 0 :(得分:1)
你应该调用transaction.success()然后调用transaction.close()。 Transaction.success()是提交事务的内容。不确定你使用演员实际调用的方法。
以下代码是我的一个项目的剪切和粘贴,用于访问嵌入GDB。
Transaction tx = graphDb.beginTx();
try{
ExecutionEngine engine = new ExecutionEngine(graphDb);
ExecutionResult result = engine.execute("MATCH (n) RETURN n");
System.out.println(result.dumpToString());
tx.success();
} finally {
tx.close();
}
答案 1 :(得分:1)
您的查询是
START n=node(*)
MATCH n-[r]-m
RETURN type(r), count(*)
ORDER BY count(*) DESC
但您尝试访问列'n'
,但未在RETURN
子句中提及它。您可能希望将查询更改为下面的查询,但这取决于您的用例。
START n=node(*)
MATCH n-[r]-m
RETURN n, type(r), count(*)
ORDER BY count(*) DESC