我是靠谱客的博主 雪白香氛,最近开发中收集的这篇文章主要介绍java导入数据 neo4j,使用Java将数据从Neo4j导出到CSV,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

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.

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 using neo4j 1.9.3 and java 1.6

解决方案

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()

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

最后

以上就是雪白香氛为你收集整理的java导入数据 neo4j,使用Java将数据从Neo4j导出到CSV的全部内容,希望文章能够帮你解决java导入数据 neo4j,使用Java将数据从Neo4j导出到CSV所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(41)

评论列表共有 0 条评论

立即
投稿
返回
顶部