2017-05-15 29 views
0

我需要以编程方式创建Neo4j数据库,然后更改初始密码。创建数据库的工作,但我不知道如何更改密码。如何在以Java编程创建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();} 

回答

0

这可能是版本依赖(我不知道你正在运行的版本),但我认为其实过程是dbms.security.changePassword

希望这有助于 汤姆

相关问题