cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Requesting Neo4j database with java application

madiskou
Graph Buddy

Hello,

I am new with neo4j, i will use the community version.
I want to know how can i request the database within a java application, i don't want to create nodes/relationships (the database is created in another project ) but i want to connect to the db and add a label for a node (my graph represents a VM's and their relationships, when there is a problem with a VM, i want to add a label for example :alert for this node which implicate changing the color + size of this node).
How can i do this? Is there several manner to do it?

Thank you,

1 REPLY 1

Hi Madiskou,

you could integrate the official neo4j java bolt driver in your project. (https://neo4j.com/docs/driver-manual/1.7/get-started/#driver-get-started-about)
When you have this driver and can create a session you could simply write a query that matches the node you'd like to update based on an id (for performance reasons you should index that id) and then set the label on the node

HashMap<String, Object> params = new HashMap<>();
params.put('id', some_id)
session.run("MATCH (vm:VM {id:$id}) SET vm:ALERT",params)"

The code above shows how you could go about this, putting the id in the run parameters allows for query caching and speedup. Here i construct a java map with the arguments and then run the query with the map added. For additional information look towards to documentation.

Hope this helps you.
Kind regards,
Joren