我是cypher的新手。我想在java中使用cypher加载csv。我用Google搜索并找到了以下内容
LOAD CSV WITH HEADERS FROM "http://neo4j.com/docs/2.3.1/csv/import/movies.csv" AS csvLine
MERGE (country:Country { name: csvLine.country })
.....
如何将此csv查询加载到java代码中。我试过这样的事。
import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.Map.Entry;
import javax.naming.spi.DirStateFactory.Result;
import org.neo4j.cypher.javacompat.ExecutionEngine;
import org.neo4j.cypher.javacompat.ExecutionResult;
import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
import org.neo4j.kernel.impl.util.FileUtils;
public class test_new {
private static final String DB_PATH = "C:...../default.graphdb";
public static void main( final String[] args ) throws IOException
{
GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase( DB_PATH );
Transaction tx1 = db.beginTx();
try{
ExecutionEngine engine = new ExecutionEngine(db);
ExecutionResult result = engine.execute("LOAD CSV WITH HEADERS FROM "C:/..../Mock_data.csv" AS csvLine ");
tx1.success();
} finally {
tx1.close();
}
db.shutdown();
}
}
但我不确定这一行。
ExecutionResult result = engine.execute("LOAD CSV WITH HEADERS FROM "C:/..../Mock_data.csv" AS csvLine ");
它会引发语法错误。
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Syntax error, insert ")" to complete MethodInvocation
Syntax error, insert ";" to complete LocalVariableDeclarationStatement
我自己不知道语法结构。如何加载csv路径?
答案 0 :(得分:1)
要更正Java语法错误,您需要在字符串中间转义双引号;否则看起来你的字符串文字在路径周围的引用处完成:
"LOAD CSV WITH HEADERS FROM \"C:/..../Mock_data.csv\" AS csvLine "
答案 1 :(得分:0)
最后这对我有用!!
ExecutionResult result = engine.execute("LOAD CSV WITH HEADERS FROM 'file:///Users/xxxxx/Documents/Txx.csv' AS csvLine ")