How can I run java and neo4j to work using bolt protocol in eclipse

244 views Asked by At

I am using maven dependencies in Eclipse and trying to connect neo4j and java using bolt protocol. I am running application in MacOS. I am using Eclipse 3 and Java version 8 and jre 1.8. This is my pom.xml **

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>org.neo4j</groupId>
  <artifactId>neo4j</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>neo4j</name>
  <url>http://maven.apache.org</url>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <dependencies>
    <dependency>
      <groupId>org.neo4j.driver</groupId>
        <artifactId>neo4j-java-driver</artifactId>
        <version>1.2.1</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.neo4j</groupId>
      <artifactId>neo4j</artifactId>
      <version>3.1.4</version>
      <scope>provided</scope>
    </dependency>   
  </dependencies>
</project>

**

This is the method called in .java file

void createDatabase()
    {
        GraphDatabaseService dfs = new GraphDatabaseFactory().newEmbeddedDatabase(dbPath);
        System.out.println("Database created!!");   
        Config noSSL = Config.build().withEncryptionLevel(Config.EncryptionLevel.NONE).toConfig();

        try(Driver dri = GraphDatabase.driver("bolt://localhost:7687", AuthTokens.basic( "neo4j", "hello" ), noSSL))
        {
            System.out.println("Database connected");

            Session session = dri.session();
            session.run("CREATE(a:Persona{name:{name}, title:{title}})", parameters("name","Aruna","title","Bhakt"));
            System.out.println("\n\t1.CREATED"); 

            StatementResult result =session.run("MATCH(a:Persona) WHERE a.name = {name}" + 
                                                    "RETURN a.name AS name, a.title AS title",
                                                    parameters("name","Aruna"));
            System.out.println("\n\t2.Match"); 

            while(result.hasNext())
            {
                Record record = result.next();
                System.out.println(record.get("title").asString() + " " + record.get("name").asString());

            }
            System.out.println("\n\t3.Found Record"); 

            session.close();
            dri.close();
        }
    }

After running the application, I am getting all this errors

Exception in thread "main" java.lang.RuntimeException: Error starting org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory, /Users/arundhatiwahane/Documents/Neo4j/default.graphdb
    at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.initFacade(GraphDatabaseFacadeFactory.java:199)
    at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.newFacade(GraphDatabaseFacadeFactory.java:130)
    at org.neo4j.graphdb.factory.GraphDatabaseFactory.newDatabase(GraphDatabaseFactory.java:101)
    at org.neo4j.graphdb.factory.GraphDatabaseFactory.lambda$createDatabaseCreator$0(GraphDatabaseFactory.java:89)
    at org.neo4j.graphdb.factory.GraphDatabaseFactory$$Lambda$1/1130478920.newDatabase(Unknown Source)
    at org.neo4j.graphdb.factory.GraphDatabaseBuilder.newGraphDatabase(GraphDatabaseBuilder.java:183)
    at org.neo4j.graphdb.factory.GraphDatabaseFactory.newEmbeddedDatabase(GraphDatabaseFactory.java:66)
    at com.sampledb.createDatabase(sampledb.java:41)
    at com.sampledb.main(sampledb.java:34)
Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.kernel.internal.StoreLockerLifecycleAdapter@1b15e2a9' was successfully initialized, but failed to start. Please see attached cause exception.
    at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:443)
    at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:107)
    at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.initFacade(GraphDatabaseFacadeFactory.java:195)
    ... 8 more
Caused by: org.neo4j.kernel.StoreLockException: Store and its lock file has been locked by another process: /Users/arundhatiwahane/Documents/Neo4j/default.graphdb/store_lock. Please ensure no other process is using this database, and that the directory is writable (required even for read-only access)
    at org.neo4j.kernel.internal.StoreLocker.storeLockException(StoreLocker.java:94)
    at org.neo4j.kernel.internal.StoreLocker.checkLock(StoreLocker.java:80)
    at org.neo4j.kernel.internal.StoreLockerLifecycleAdapter.start(StoreLockerLifecycleAdapter.java:40)
    at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:433)
    ... 10 more

Kindly help me to figure all my errors.

1

There are 1 answers

3
whoopdedoo On

Another process is locking, kill it

try

ps aux | grep neo4j

or

ps aux | grep java

read your exception's description

Caused by: org.neo4j.kernel.StoreLockException: Store and its lock file has been locked by another process: /Users/arundhatiwahane/Documents/Neo4j/default.graphdb/store_lock. Please ensure no other process is using this database, and that the directory is writable (required even for read-only access)

if killing the process did not solve you need to add write permission to directory

chmod -R 777 /Users/arundhatiwahane/Documents/Neo4j/