用javaapi连接neo4j数据库



早上好,

在neo4j中执行此查询时出错:查询不能以USE GRAPH(必须是RETURN或update子句((第1行第5列(偏移量:4((结束

"使用eindb">

package org.einaudi.impfilesjson;
import org.neo4j.driver.AuthTokens;
import org.neo4j.driver.Driver;
import org.neo4j.driver.GraphDatabase;
import org.neo4j.driver.Result;
import org.neo4j.driver.Session;
public class App implements AutoCloseable {

private final Driver driver;

public App(String uri, String user, String password) {
driver = GraphDatabase.driver( uri, AuthTokens.basic( user, password ) );
}

@Override
public void close() throws Exception
{
driver.close();
}

public void print greeting( final String message )
{
try ( Session session = driver.session() )
{
Result res = session.run( "USE eindb;" );
System.out.println(res.toString());
}
}

public static void main( String[] args ){
System.out.println( "Hello World!" );

App app;

try {

app = new App( "bolt://localhost:11003", "neo4j", "Admpa" );
app.printGreeting( "hello, world" );
}catch(Exception e) {
System.out.println(e.getMessage());
}

}
}

如何通过java API在neo4j中选择特定的数据库?

本节文档将对您有所帮助。https://neo4j.com/docs/java-manual/current/cypher-workflow/#java-数据库选择

这将设置一个名为";foo";作为会话的默认值。

try ( Session session = driver.session(SessionConfig.forDatabase( "foo" )) )

您也可以在密码查询中指定数据库,但您需要的不仅仅是USE子句。

Result res = session.run( "USE eindb match (n) return count(n) as nodeCount" );

相关内容

  • 没有找到相关文章

最新更新