Database Reference
In-Depth Information
Listing 12-7. Deleting a Node
public void DeleteNode() {
// Make sure Neo4j Driver is registered
Class.forName("org.neo4j.jdbc.Driver");
// Connect
Connection conn = DriverManager.getConnection("jdbc:neo4j://localhost:7474/");
Map<String, Object> params = map("1", “Greg”);
String query= " MATCH (user:User {name:{1}}) " +
" DELETE user ";
final PreparedStatement statement = conn.prepareStatement(query);
for (Map.Entry<String, Object> entry : params.entrySet()) {
int index = Integer.parseInt(entry.getKey());
statement.setObject(index, entry.getValue());
}
final ResultSet result = statement.executeQuery();
}
Creating a Relationship
To create a basic relationship, you need at a minimum one distinct node and to know ahead of time the name of the
relationship you would like to use. Listing 12-8 creates a relationship called FOLLOWS between two user nodes by
matching on their names and using CREATE UNIQUE to establish the relationship.
Both the start and end nodes of a relationship must already be established within the database before the
relationship can be saved.
Note
Listing 12-8. Relating Two Nodes
public void CreateRelationship() {
// Make sure Neo4j Driver is registered
Class.forName("org.neo4j.jdbc.Driver");
// Connect
Connection conn = DriverManager.getConnection("jdbc:neo4j://localhost:7474/");
Map<String, Object> params = map("1", "Greg", "2", "Jeremy");
 
 
Search WWH ::




Custom Search