Database Reference
In-Depth Information
Listing 12-11. Adding Labels to a Node
public void AddLabels() {
// Make sure Neo4j Driver is registered
Class.forName("org.neo4j.jdbc.Driver");
// Connect
Connection conn = DriverManager.getConnection("jdbc:neo4j://localhost:7474/");
// uses a Node Id for the param in the WHERE clause
Map<String, Object> params = map("1", 1);
String query= " MATCH (n) "+
" WHERE id(n) = {1} "+
" SET n :Developer :Admin "+
" RETURN n ";
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();
}
Removing a Label
Removing a label uses nearly identical syntax as adding labels to a node, except that you change the SET clause to a
REMOVE clause. After the given label has been removed from the node, the return value is the node (Listing 12-12).
Listing 12-12. Removing a Label from a Node
public void RemoveLabels() {
// Make sure Neo4j Driver is registered
Class.forName("org.neo4j.jdbc.Driver");
// Connect
Connection conn = DriverManager.getConnection("jdbc:neo4j://localhost:7474/");
// uses a Node Id for the param in the WHERE clause
Map<String, Object> params = map("1", 1);
String query= " MATCH (n) "+
" WHERE id(n) = {1} "+
" REMOVE n :Developer :Admin "+
" RETURN n ";
 
Search WWH ::




Custom Search