Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get java and neo4j to work in eclipse

I am using mint 17.2 and have neo4j 3.06 Comunity Edition it is running fine on localhost:7474.

I wish to program in Java 1.08, using Eclipse Mars 2 but I cannot get it to work.

I am using a maven project and have the following in 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>com.geekcap.informit</groupId>
  <artifactId>neo4j-sample-app</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>neo4j-sample-app</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.neo4j.driver</groupId>
        <artifactId>neo4j-java-driver</artifactId>
        <version>1.0.3</version>
    </dependency>
  </dependencies>
</project>

I have the following in my app.java file

package com.geekcap.informit.neo4j_sample_app;


import org.neo4j.driver.v1.*;

public class App 
{

    public static void main( String[] args )
    {
      Driver driver = GraphDatabase.driver("bolt://localhost:7474", AuthTokens.basic("neo4j", "neo4j"));
      Session session = driver.session();

      session.run("CREATE (a:Person {name:'Arthur', title:'King'})" );

      StatementResult result = 
          session.run("Match (a:Person) WHERE a.name = 'Arthur' RETURN a.name AS name, a.title AS title");
      while (result.hasNext()) {
        Record record = result.next();
        System.out.println(record.get("title").asString() + " " + 
            record.get("name").asString());
      }

      session.close();
      driver.close();
    }

I get the following error when I try to run it as a java application.

Exception in thread "main" org.neo4j.driver.v1.exceptions.ClientException: Unable to process request: Unrecognized SSL message, plaintext connection?
  at org.neo4j.driver.internal.connector.socket.SocketClient.start(SocketClient.java:87)
  at org.neo4j.driver.internal.connector.socket.SocketConnection.<init>(SocketConnection.java:63)
  at org.neo4j.driver.internal.connector.socket.SocketConnector.connect(SocketConnector.java:52)
  at org.neo4j.driver.internal.pool.InternalConnectionPool$1.allocate(InternalConnectionPool.java:191)
  at org.neo4j.driver.internal.pool.InternalConnectionPool$1.allocate(InternalConnectionPool.java:180)
  at org.neo4j.driver.internal.pool.ThreadCachingPool.allocate(ThreadCachingPool.java:212)
  at org.neo4j.driver.internal.pool.ThreadCachingPool.acquireFromGlobal(ThreadCachingPool.java:164)
  at org.neo4j.driver.internal.pool.ThreadCachingPool.acquire(ThreadCachingPool.java:118)
  at org.neo4j.driver.internal.pool.InternalConnectionPool.acquire(InternalConnectionPool.java:109)
  at org.neo4j.driver.internal.InternalDriver.session(InternalDriver.java:53)
  at com.geekcap.informit.neo4j_sample_app.App.main(App.java:12)
Caused by: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
  at sun.security.ssl.EngineInputRecord.bytesInCompletePacket(EngineInputRecord.java:156)
  at sun.security.ssl.SSLEngineImpl.readNetRecord(SSLEngineImpl.java:868)
  at sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:781)
  at javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:624)
  at org.neo4j.driver.internal.connector.socket.TLSSocketChannel.unwrap(TLSSocketChannel.java:186)
  at org.neo4j.driver.internal.connector.socket.TLSSocketChannel.runHandshake(TLSSocketChannel.java:127)
  at org.neo4j.driver.internal.connector.socket.TLSSocketChannel.<init>(TLSSocketChannel.java:95)
  at org.neo4j.driver.internal.connector.socket.TLSSocketChannel.<init>(TLSSocketChannel.java:77)
  at org.neo4j.driver.internal.connector.socket.TLSSocketChannel.<init>(TLSSocketChannel.java:70)
  at org.neo4j.driver.internal.connector.socket.SocketClient$ChannelFactory.create(SocketClient.java:235)
  at org.neo4j.driver.internal.connector.socket.SocketClient.start(SocketClient.java:74)
  ... 10 more
like image 404
Laurence Avatar asked Sep 27 '16 10:09

Laurence


People also ask

Does Neo4j support Java?

The Neo4j Java driver is officially supported by Neo4j and connects to the database using the binary protocol. It aims to be minimal, while being idiomatic to Java. We support Java 8 and 11 for the driver. For other build systems, see information available at Maven Central.

Which protocols can be used to connect to Neo4j?

Neo4j officially supports the drivers for . Net, Java, JavaScript, Go, and Python for the binary Bolt protocol. Our community contributors provide drivers for all major programming languages for all protocols and APIs.

How do I connect to a Neo4j database?

Neo4j Browser is the easiest way to access a Neo4j database. To establish a connection, you enter the DBMS URL, the name of the database you want to connect, and the user credentials. You can also use the :server command to manage the connection to Neo4j. For more information, see Manage connection commands.


1 Answers

The 7474 port is the HTTP port. Since you're using the bolt:// protocol, you should connect to the 7687 port. Or actually remove the port since it's the default value:

Driver driver = GraphDatabase.driver("bolt://localhost", AuthTokens.basic("neo4j", "neo4j"));

Also make sure that the Bolt protocol is actually active on the Neo4j instance, by uncommenting in conf/neo4j.conf (remove the preceding #):

dbms.connector.bolt.address=0.0.0.0:7687

or at least, to limit to local connections:

dbms.connector.bolt.address=127.0.0.1:7687
like image 158
Frank Pavageau Avatar answered Oct 03 '22 08:10

Frank Pavageau