使用Java将数据从Neo4j导出到CSV [英] exporting data from Neo4j to csv using java

查看:420
本文介绍了使用Java将数据从Neo4j导出到CSV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是将数据从Neo4j导出到CSV的最佳方法,我已经在链接 https://github.com/sroycode/neo4j-import .

what is the best methodology to export data from Neo4j to CSV, I had imported data from csv to neo4j using CSV importer in the link https://github.com/sroycode/neo4j-import.

我已经对数据执行了一些操作,我想将查询结果返回到csv中,有人可以向我建议解决方案.

I had performed some operations on the data, i want to get back the query results into the csv, can anyone suggest me the solution.

iam使用neo4j 1.9.3和Java 1.6

iam using neo4j 1.9.3 and java 1.6

推荐答案

Groovy中的一小段代码可以这样做:

A short snippet in Groovy doing this:

@Grab(group="org.neo4j", module="neo4j-cypher", version="1.9")
@Grab(group='net.sf.opencsv', module='opencsv', version='2.3') 
import org.neo4j.kernel.EmbeddedGraphDatabase
import org.neo4j.cypher.javacompat.ExecutionEngine
import au.com.bytecode.opencsv.CSVWriter

assert args, "specify location of graph.db and cypher statement"

def db = new org.neo4j.kernel.EmbeddedGraphDatabase(args[0])
def ee = new ExecutionEngine(db)
def result = ee.execute(args[1])
def columns = result.columns()

System.out.withWriter { writer ->
    CSVWriter csv = new CSVWriter(writer)
    csv.writeNext(columns as String[])

    for (def row in result) {
        def values = columns.collect {row[it]}
        csv.writeNext(values as String[])
    }
}
db.shutdown()

当然opencsv也可以在纯Java环境中使用.

Of course opencsv can be used in a pure Java environment as well.

这篇关于使用Java将数据从Neo4j导出到CSV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆