To connect Android Studio to Neo4j, you can follow the below steps:
dependencies {
compile group:'org.neo4j.driver', name:'neo4j-java-driver', version:'4.0.0'
}
import org.neo4j.driver.AuthTokens;
import org.neo4j.driver.Driver;
import org.neo4j.driver.GraphDatabase;
public class Neo4jConnection {
private final Driver driver;
private final String uri;
private final String username;
private final String password;
public Neo4jConnection(String uri, String username, String password) {
this.uri = uri;
this.username = username;
this.password = password;
this.driver = GraphDatabase.driver(uri, AuthTokens.basic(username, password));
}
public Driver getDriver() {
return this.driver;
}
}
private Neo4jConnection neo4jConnection;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
neo4jConnection = new Neo4jConnection("bolt://localhost:7687", "username", "password");
}
try (Session session = neo4jConnection.getDriver().session()) {
session.writeTransaction(tx -> tx.run("CREATE (n:Person {name: $name})", parameters("name", "John")));
}
This code will create a new node in the Neo4j graph database with the label "Person" and the value "John" for the "name" property.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-05-11 05:59:32 +0000
Seen: 18 times
Last updated: May 11 '23
What are the typical approaches found in a Gradle build script?
What steps can be taken to increase the runtime of a debugger in NativeScript?
What is the method to show the dependencies in Java?
How can I incorporate BeanComparator into my gradle project?
What does the "Invalid source release 1.7" error mean when using gradle for compilation?