String connectionUrl = "jdbc:neo4j:bolt+routing://localhost:17681,localhost:17682,localhost:17683,localhost:17684,localhost:17685,localhost:17686,localhost:17687?noSsl&routing:policy=EU";
try (Connection connection = DriverManager.getConnection(connectionUrl, "neo4j", password)) {
connection.setAutoCommit(false);
// Access to CORE nodes, as the connection is opened by default in write mode
try (Statement statement = connection.createStatement()) {
statement.execute("create (:BoltRoutingTest { protocol: 'BOLT+ROUTING' })");
}
// closing transaction before changing access mode
connection.commit();
// printing the transaction bookmark
String bookmark = connection.getClientInfo(BoltRoutingNeo4jDriver.BOOKMARK);
System.out.println(bookmark);
// Switching to read-only mode to access READ REPLICA nodes
connection.setReadOnly(true);
try (Statement statement = connection.createStatement()) {
try (ResultSet resultSet = statement.executeQuery("match (t:BoltRoutingTest) return count(t) as tot")) {
if (resultSet.next()) {
Long tot = resultSet.getLong("tot");
}
}
}
connection.commit();
}