Java应用程序中的Neo4j查询:没有显示结果[仍然无法解决它]
更新的问题 这个问题是基于我先前的和neo4j 我想找出住在城市里的人。 我使用了两个节点:person和city,这两个节点之间的关系是(person)-[:LIVES\u IN]->(city) 在遵循导师在我之前的帖子中给出的建议后,我做了一些修改 但它只显示为该城市添加的当前人名 我的代码如下:(这里保留3个文本框、2个按钮和1个文本区域)Java应用程序中的Neo4j查询:没有显示结果[仍然无法解决它],java,swing,nosql,neo4j,cypher,Java,Swing,Nosql,Neo4j,Cypher,更新的问题 这个问题是基于我先前的和neo4j 我想找出住在城市里的人。 我使用了两个节点:person和city,这两个节点之间的关系是(person)-[:LIVES\u IN]->(city) 在遵循导师在我之前的帖子中给出的建议后,我做了一些修改 但它只显示为该城市添加的当前人名 我的代码如下:(这里保留3个文本框、2个按钮和1个文本区域) 导入java.io.File; 导入java.io.IOException; 导入java.util.ArrayList; 导入java.util.
导入java.io.File;
导入java.io.IOException;
导入java.util.ArrayList;
导入java.util.HashMap;
导入org.neo4j.graphdb.GraphDatabaseService;
导入org.neo4j.graphdb.Node;
导入org.neo4j.graphdb.RelationshipType;
导入org.neo4j.graphdb.Transaction;
导入org.neo4j.graphdb.factory.GraphDatabaseFactory;
导入org.neo4j.helpers.collection.IteratorUtil;
导入java.util.Iterator;
导入java.util.List;
导入java.util.Map;
导入java.util.Map.Entry;
导入org.neo4j.cypher.javacompat.ExecutionEngine;
导入org.neo4j.cypher.javacompat.ExecutionResult;
导入org.neo4j.graphdb.Label;
导入org.neo4j.graphdb.schema.IndexDefinition;
导入org.neo4j.graphdb.schema.schema;
枚举标签实现标签{
人,
城市
}
公共类注册框架扩展了javax.swing.JFrame{
公共静态最终字符串DB_PATH=“D://data”;
公共静态GraphDatabaseService graphDb=null;
节点人;
节点密码;
节点城市;
字符串nodeResulta;
字符串行=”;
Schema=null;
布尔e=false;
私有void jButton1ActionPerformed(java.awt.event.ActionEvent evt){
//创建人员和人员节点时的架构索引
try(事务tx=graphDb.beginTx()){
schema=graphDb.schema();
对于(IndexDefinition id:graphDb.schema().getIndexes()){
e=真;
}
如果(!e)
schema.indexFor(labels.Person).on(“name”).create();
成功();
}
try(事务tx=graphDb.beginTx();){
person=graphDb.createNode(labels.person);
person.setProperty(“name”,jTextField1.getText());
person.setProperty(“密码”,jPasswordField1.getPassword());
graphDb.index().forNodes(“name”).add(person,“name”,jTextField1.getText());
成功();
}
//城市和城市节点创建和关系建立的模式索引
try(事务tx=graphDb.beginTx()){
schema=graphDb.schema();
对于(IndexDefinition id:graphDb.schema().getIndexes()){
e=真;
}
如果(!e)
schema.indexFor(labels.City).on(“City_name”).create();
成功();
}
try(事务tx=graphDb.beginTx();){
city=graphDb.createNode(labels.city);
setProperty(“city_name”,jTextField2.getText());
graphDb.index().forNodes(“city_name”).add(city,“city_name”,jTextField2.getText());
person.createRelationshipTo(城市,RelTypes.LIVES_);
成功();
}
}
私有void jButton2ActionPerformed(java.awt.event.ActionEvent evt){
ExecutionEngine=新的ExecutionEngine(graphDb);
执行结果;
字符串temp=jTextField2.getText();
Map params=新的HashMap();
try(事务被忽略=graphDb.beginTx()){
参数put(“c_名称”,临时);
//**Luane建议的查询,用于查找居住在同一城市的人**
result=engine.execute(“MATCH(city:city{city_name:{c_name}})尝试使用更简单的密码
执行以下操作以加快速度。同时使用
在Neo4j浏览器中对模型进行原型化,直到您的所有创建和查询语句都能正常工作
然后使用那些带有参数占位符的cypher语句,例如通过executionEngine.execute(query,params)
从程序中输入的{name}
现在你有太多的活动部件,解释一个部件对你学习概念没有帮助。试着坚持使用密码,这样会更容易 执行以下操作以加快速度。同时使用 在Neo4j浏览器中对模型进行原型化,直到您的所有创建和查询语句都能正常工作 然后使用那些带有参数占位符的cypher语句,例如通过executionEngine.execute(query,params)从程序中输入的
{name}
现在你有太多的活动部件,解释一个部件对你学习概念没有帮助。试着坚持使用密码,这样会更容易 执行以下操作以加快速度。同时使用 在Neo4j浏览器中对模型进行原型化,直到您的所有创建和查询语句都能正常工作 然后使用那些带有参数占位符的cypher语句,例如通过executionEngine.execute(query,params)从程序中输入的
{name}
现在你有太多的活动部件,解释一个部件对你学习概念没有帮助。试着坚持使用密码,这样会更容易 执行以下操作以加快速度。同时使用 在Neo4j浏览器中对模型进行原型化,直到您的所有创建和查询语句都能正常工作 然后使用那些带有参数占位符的cypher语句,例如通过executionEngine.execute(query,params)从程序中输入的
{name}
现在你有太多的运动部件和解释一个部件
import java.io.File;
import java.io.IOException;
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.List;
import java.util.Map;
import java.util.Map.Entry;
import org.neo4j.cypher.javacompat.ExecutionEngine;
import org.neo4j.cypher.javacompat.ExecutionResult;
import org.neo4j.graphdb.Label;
import org.neo4j.graphdb.schema.IndexDefinition;
import org.neo4j.graphdb.schema.Schema;
enum labels implements Label {
Person,
City
}
public class registrationFrame extends javax.swing.JFrame {
public static final String DB_PATH = "D://data";
public static GraphDatabaseService graphDb = null;
Node person;
Node password;
Node city;
String nodeResulta;
String rows = "";
Schema schema = null;
boolean e = false;
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
//Schema index on Person and person node creation
try (Transaction tx = graphDb.beginTx()) {
schema = graphDb.schema();
for (IndexDefinition id : graphDb.schema().getIndexes()) {
e = true;
}
if (!e)
schema.indexFor(labels.Person).on("name").create();
tx.success();
}
try (Transaction tx = graphDb.beginTx();) {
person = graphDb.createNode(labels.Person);
person.setProperty("name", jTextField1.getText());
person.setProperty("password", jPasswordField1.getPassword());
graphDb.index().forNodes("name").add(person, "name", jTextField1.getText());
tx.success();
}
//Schema index on City and city node creation and relationship establishment
try (Transaction tx = graphDb.beginTx()) {
schema = graphDb.schema();
for (IndexDefinition id : graphDb.schema().getIndexes()) {
e = true;
}
if (!e)
schema.indexFor(labels.City).on("city_name").create();
tx.success();
}
try (Transaction tx = graphDb.beginTx();) {
city = graphDb.createNode(labels.City);
city.setProperty("city_name", jTextField2.getText());
graphDb.index().forNodes("city_name").add(city, "city_name", jTextField2.getText());
person.createRelationshipTo(city, RelTypes.LIVES_IN);
tx.success();
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
ExecutionEngine engine = new ExecutionEngine(graphDb);
ExecutionResult result;
String temp=jTextField2.getText();
Map<String,Object> params=new HashMap<>();
try (Transaction ignored = graphDb.beginTx()) {
params.put("c_name",temp);
// **the query advised by Luanne for finding person living in same city**
result=engine.execute("MATCH (city:City {city_name:{c_name}})<-[:LIVES_IN]-(person) RETURN person",params);
System.out.println(result);
Iterator<Node> n_column = result.columnAs("person");
for (Node node : IteratorUtil.asIterable(n_column)) {
System.out.println("hiii");
nodeResulta = node + ": " + node.getProperty("name") + '\n';
}
// END SNIPPET: items
}
jTextArea1.setText(nodeResulta);
}
public static enum RelTypes implements RelationshipType {
LIVES_IN,
FRIEND,
CUISINE,
LIKES,
IN
}
}