Я новичок в Java и neo4j.Попытка моего первого подключения к neo4j с помощью приложения JavaЯ не могу понять, почему я получаю сообщение об ошибке: Exception in thread "main" org.neo4j.driver.v1.exceptions.AuthenticationException: The client is unauthorized due to authentication failure.
- Болт: болт: // localhost: 7687 (рабочий стол neo4j на моем macbook)
- GraphName: PrakashTest1
- Пароль: 12345678
Java-приложение:
import org.neo4j.driver.v1.AuthTokens;
import org.neo4j.driver.v1.Driver;
import org.neo4j.driver.v1.GraphDatabase;
import org.neo4j.driver.v1.Session;
import org.neo4j.driver.v1.StatementResult;
import org.neo4j.driver.v1.Transaction;
import org.neo4j.driver.v1.TransactionWork;
import static org.neo4j.driver.v1.Values.parameters;
public class HelloWorldExample implements AutoCloseable {
private final Driver driver;
public HelloWorldExample( String uri, String user, String password )
{
driver = GraphDatabase.driver( uri, AuthTokens.basic( user, password ) );
}
@Override
public void close() throws Exception
{
driver.close();
}
public void printGreeting( final String message ) {
try ( Session session = driver.session() )
{
String greeting = session.writeTransaction( new TransactionWork<String>()
{
@Override
public String execute( Transaction tx )
{
StatementResult result = tx.run( "CREATE (a:Greeting) " +
"SET a.message = $message " +
"RETURN a.message + ', from node ' + id(a)",
parameters( "message", message ) );
return result.single().get( 0 ).asString();
}
} );
System.out.println( greeting );
}
}
public static void main( String... args ) throws Exception
{
try ( HelloWorldExample greeter = new HelloWorldExample( "bolt://localhost:7687", "PrakashTest1", "12345678" ) )
{
greeter.printGreeting( "hello, world" );
}
}
}