简体   繁体   English

java 中的 cypher 查询:获取和迭代结果集节点

[英]cypher query in java: get and iterate resultset nodes

public class BooksManager {
    
    //private final Driver driver;
    private final ConnectionConfig config;
    private Connection con;
    public BooksManager(ConnectionConfig config) {
        this.config = config;
        this.con = null;
        try {
            this.con = DriverManager.getConnection("jdbc:neo4j:"+ config.getFullUrl(), "neo4j", config.getPassword());
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
    }

public void viewBook(){
    booksQuery = "USE eindb MATCH (b:Book) RETURN b LIMIT 25";

    PreparedStatement stmt = null;
    try {
        stmt = con.prepareStatement(booksQuery);
    } catch (SQLException e1) {
        e1.printStackTrace();
    }
        
    ResultSet rs = null;
        
    try {
        rs = stmt.executeQuery();
    } catch (SQLException e2) {
        e2.printStackTrace();
    }
        
    try {
        while (rs.next()) {
            
            Object bookJustObject = rs.getObject("b");
            System.out.println("b: "+bookJustObject);
            //TODO get all fields from object, how? 
        }

    } catch (SQLException e1) {
        e1.printStackTrace();
    }
}


I execute successfull query which return some books.我执行成功的查询,返回一些书。 Query run with jdbc connection for neo4j database.使用 neo4j 数据库的 jdbc 连接运行查询。 I don't understand how to list all fields from object "b" which represents a book in graph database.我不明白如何列出 object "b" 中的所有字段,它代表图形数据库中的一本书。

It depends on what you want.这取决于你想要什么。 Some pointers:一些指示:

to return a specific set of properties返回一组特定的属性

RETURN b.title AS title, b.foo AS foo

to return properties as a map:以 map 的形式返回属性:

RETURN properties(b) AS map

to return properties and add the node id.返回属性并添加节点 ID。

RETURN apoc.map.setKey(properties(b),'id',id(b)) AS mapWithId

to return a list of all properties/keys返回所有属性/键的列表

MATCH (b:Book) 
UNWIND keys(b) AS key
RETURN DISTINCT key

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM