Skip to content

Instantly share code, notes, and snippets.

Created August 23, 2019 21:39
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
neo4j 4.0 example
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.logging.Level;
import static java.util.concurrent.TimeUnit.SECONDS;
import java.time.Duration;
import java.time.Instant;
import org.neo4j.driver.internal.logging.ConsoleLogging;
import org.neo4j.driver.AuthToken;
import org.neo4j.driver.AuthTokens;
import org.neo4j.driver.Config;
import org.neo4j.driver.Driver;
import org.neo4j.driver.GraphDatabase;
import org.neo4j.driver.Record;
import org.neo4j.driver.Session;
import org.neo4j.driver.StatementResult;
import org.neo4j.driver.Transaction;
import org.neo4j.driver.exceptions.ServiceUnavailableException;
import org.neo4j.driver.*;
import org.reactivestreams.*;
import static org.neo4j.driver.SessionConfig.builder;
import static org.neo4j.driver.Values.parameters;
public class Neo4jDriverTest {
private static final Config config =
.withLogging( new ConsoleLogging( Level.FINE ) )
.withMaxTransactionRetryTime( 60, SECONDS )
.withTrustStrategy( Config.TrustStrategy.trustAllCertificates()).toConfig();
public static void main(String[] argv) throws Exception {
System.out.println("-------- Neo4j Bolt Connection Testing ------");
Transaction transaction;
List<String> uris = new ArrayList<String>();
Driver driver = null;
int i=0;
for (i =0; i<1; i++){
int j = 100;
// driver = acquireDriver(uris,AuthTokens.basic( "neo4j", "password" ),config );
driver = GraphDatabase.driver( "neo4j://localhost:7687", AuthTokens.basic( "Neo4j Admin", "neo4j" ) );
Instant start =;
try (Session session = driver.session( builder().withDatabase( "iam" ).withDefaultAccessMode( AccessMode.WRITE ).build() ) )
transaction = session.beginTransaction();
for (i =0; i<30; i++){"unwind range(1,20000) as id create (:Person{id:id})");
//"CREATE (a:Person {name: $name})", parameters( "name", "smith" ) );
Instant end =;
Duration timeElapsed = Duration.between(start, end);
System.out.println("Time taken: "+ timeElapsed.toMillis() +" milliseconds");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment