Database Reference
In-Depth Information
Deleting a Relationship
Once a relationship's graph id has been set and saved into the database, it becomes eligible to be removed when
necessary (Listing 12-10).
Listing 12-10. Deleting a Relationship
public void DeleteRelationship() {
// 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”);
String query= " MATCH (u1:User { name:{1}})-[rel:FOLLOWS]->(u2:User { name:{2}}) " +
" DELETE rel ";
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();
}
Using Labels
Labels function as specific meta-descriptions that can be applied to nodes. Labels were introduced in Neo4j 2.0 in
order to support index querying and can also function as a way to quickly create a subgraph.
Adding a Label to Nodes
For existing nodes, you can add one more labels by using the SET clause. As Listing 12-11 shows, you first find the
node using the MATCH clause and then SET one (or more) labels.
Caution
A label will not exist on the database server until it has been added to at least one node.
 
 
Search WWH ::




Custom Search