如何在Java中以编程方式创建Neo4j数据库时更改初始密码

时间:2017-05-15 20:27:31

标签: java neo4j

我需要以编程方式创建Neo4j数据库,然后更改初始密码。创建数据库有效,但我不知道如何更改密码。

        String graphDBFilePath = Config.getNeo4jFilesPath_Absolute() + "/" + schemaName;        // This is an absolute path. Do not let Neo4j see it.
        GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase( new File(graphDBFilePath) ); // See http://neo4j.com/docs/java-reference/current/javadocs/org/neo4j/graphdb/GraphDatabaseService.html

        // This transaction works
        try (Transaction tx = graphDb.beginTx()) {
            Node myNode = graphDb.createNode();
            myNode.setProperty( "name", "my node");
            tx.success();
        }
         // This transaction throws an error
         Transaction tx = graphDb.beginTx();
         try {
             graphDb.execute("CALL dbms.changePassword(\'Danger42\')");     // "Invalid attempt to change the password" error
             tx.success();
         } catch (Exception ex) {
                Log.logError("createNewGraphDB() Change Initial Password: " + ex.getLocalizedMessage());
         } finally {tx.close(); graphDb.shutdown();}

1 个答案:

答案 0 :(得分:0)

这可能与版本有关(我不知道你在运行什么版本),但我认为该程序实际上是 dbms.security.changePassword

希望这有帮助, 汤姆