# Java driver issue

**URL:** <https://community.neo4j.com/t/java-driver-issue/44166>\
**Category:** Java\
**Created:** [September 9, 2021, 3:24pm UTC](https://community.neo4j.com/t/java-driver-issue/44166 "2021-09-09T15:24:27Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![jzhou002](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/jzhou002/32/16912_2.png) [@jzhou002](https://community.neo4j.com/u/jzhou002)\
**Post date:** [September 9, 2021, 3:24pm UTC](https://community.neo4j.com/t/java-driver-issue/44166/1 "2021-09-09T15:24:27Z")

</div>

Hi, I have read jdbc driver issue before, right I have the same issue. Here is the example I copied from neo4j website, it runs with jdbc error.

```auto
import org.neo4j.driver.*;
import static org.neo4j.driver.Values.parameters;

public class SmallExample
{
	    // Driver objects are thread-safe and are typically made available application-wide.
	    Driver driver;

	    public SmallExample(String uri, String user, String password)
	    {
	        driver = GraphDatabase.driver(uri, AuthTokens.basic(user, password));
	       
	    }

	    private void addPerson(String name)
	    {
	        // Sessions are lightweight and disposable connection wrappers.
	        try (Session session = driver.session())
	        {
	            // Wrapping a Cypher Query in a Managed Transaction provides atomicity
	            // and makes handling errors much easier.
	            // Use `session.writeTransaction` for writes and `session.readTransaction` for reading data.
	            // These methods are also able to handle connection problems and transient errors using an automatic retry mechanism.
	            session.writeTransaction(tx -> tx.run("MERGE (a:Person {name: $x})", parameters("x", name)));
	        }
	    }

	    private void printPeople(String initial)
	    {
	        try (Session session = driver.session())
	        {
	            // A Managed transaction is a quick and easy way to wrap a Cypher Query.
	            // The `session.run` method will run the specified Query.
	            // This simpler method does not use any automatic retry mechanism.
	            Result result = session.run(
	                    "MATCH (a:Person) WHERE a.name STARTS WITH $x RETURN a.name AS name",
	                    parameters("x", initial));
	            // Each Cypher execution returns a stream of records.
	            while (result.hasNext())
	            {
	                org.neo4j.driver.Record record = result.next();
	                // Values can be extracted from a record by index or name.
	                System.out.println(record.get("name").asString());
	            }
	        }
	    }

	    public void close()
	    {
	        // Closing a driver immediately shuts down all open connections.
	        driver.close();
	    }
   
	    public static void main(String... args)
	    {
	        SmallExample example = new SmallExample("bolt://localhost:7687", "neo4j", "password");
	        example.addPerson("Ada");
	        example.addPerson("Alice");
	        example.addPerson("Bob");
	        example.printPeople("A");
	        example.close();
	    }
}

```

The error is "INFO: Closing connection pool towards localhost:7687  
java.sql.SQLException: org.neo4j.driver.v1.exceptions.ServiceUnavailableException: Connection to the database terminated. This can happen due to network instabilities, or due to restarts of the database." error points to this line:

```auto
driver = GraphDatabase.driver(uri, AuthTokens.basic(user, password));

```

Any helps are appreicated. Thanks.

---

<div class="post-metadata">

**Author:** ![akollegger1](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/akollegger1/32/14828_2.png) [@akollegger1](https://community.neo4j.com/u/akollegger1)\
**Post date:** [September 13, 2021, 12:51pm UTC](https://community.neo4j.com/t/java-driver-issue/44166/2 "2021-09-13T12:51:16Z")

</div>

Hi @jzhou002 ,

A few questions:

How are you running Neo4j?

Are you able to connect to the local server using Neo4j browser? With the Neo4j DBMS running, try opening a web browser at [http://localhost:7474](http://localhost:7474) -- this should load the Neo4j Browser, where you can login to the database.

Is the connection string used by Neo4j Browser the same as you are using in the driver?

Best,  
ABK

---

<div class="post-metadata">

**Author:** ![jzhou002](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/jzhou002/32/16912_2.png) [@jzhou002](https://community.neo4j.com/u/jzhou002)\
**Post date:** [September 13, 2021, 1:22pm UTC](https://community.neo4j.com/t/java-driver-issue/44166/3 "2021-09-13T13:22:35Z")

</div>

Hi Adreas, thanks for the reply. I run neo4j locally, I can use Chrome to connect to neo4j [http://localhost?:7687](http://localhost?:7687) port, that part runs smoothly. The java program I used was copied/paste from neo4j examples, the error points to jdbc:neo4j.bolt://localhost, it seems the uri got nulled by the jdbc driver. So I do not know what else I should look at.  
Thanks.

---

<div class="post-metadata">

**Author:** ![florent\_biville](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/florent_biville/32/14205_2.png) [@florent\_biville](https://community.neo4j.com/u/florent_biville)\
**Post date:** [September 13, 2021, 1:42pm UTC](https://community.neo4j.com/t/java-driver-issue/44166/4 "2021-09-13T13:42:26Z")

</div>

Hello, you are using a JDBC URI with a non-JDBC driver, so it is not going to work.  
The code you posted is an example of using the native Java Bolt driver, not a JDBC driver.  
The URI you want to use here is `bolt://localhost`.

P.S.: if you could point us to the README you were reading, there is probably something we need to fix there

---

<div class="post-metadata">

**Author:** ![jzhou002](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/jzhou002/32/16912_2.png) [@jzhou002](https://community.neo4j.com/u/jzhou002)\
**Post date:** [September 13, 2021, 4:03pm UTC](https://community.neo4j.com/t/java-driver-issue/44166/5 "2021-09-13T16:03:19Z")

</div>

This is also from neo4j example, it uses "bolt://localhost", and error point to the uri

```java
import org.neo4j.driver.*;
import org.neo4j.driver.exceptions.DatabaseException;
import static org.neo4j.driver.Values.parameters;

public class SmallExample
{
	    // Driver objects are thread-safe and are typically made available application-wide.
	    Driver driver;

	    public SmallExample(String uri, String user, String password) throws DatabaseException
	    {
	        driver = GraphDatabase.driver(uri, AuthTokens.basic(user, password));
	        driver.verifyConnectivity();
	    }

	    private void addPerson(String name)
	    {
	        // Sessions are lightweight and disposable connection wrappers.
	        try (Session session = driver.session())
	        {
	            // Wrapping a Cypher Query in a Managed Transaction provides atomicity
	            // and makes handling errors much easier.
	            // Use `session.writeTransaction` for writes and `session.readTransaction` for reading data.
	            // These methods are also able to handle connection problems and transient errors using an automatic retry mechanism.
	            session.writeTransaction(tx -> tx.run("MERGE (a:Person {name: $x})", parameters("x", name)));
	        }
	    }

	    private void printPeople(String initial)
	    {
	        try (Session session = driver.session())
	        {
	            // A Managed transaction is a quick and easy way to wrap a Cypher Query.
	            // The `session.run` method will run the specified Query.
	            // This simpler method does not use any automatic retry mechanism.
	            Result result = session.run(
	                    "MATCH (a:Person) WHERE a.name STARTS WITH $x RETURN a.name AS name",
	                    parameters("x", initial));
	            // Each Cypher execution returns a stream of records.
	            while (result.hasNext())
	            {
	                org.neo4j.driver.Record record = result.next();
	                // Values can be extracted from a record by index or name.
	                System.out.println(record.get("name").asString());
	            }
	        }
	    }

	    public void close()
	    {
	        // Closing a driver immediately shuts down all open connections.
	        driver.close();
	    }
   
	    public static void main(String... args)
	    {
	        SmallExample example = new SmallExample("bolt://localhost:7687", "neo4j", "password");
	        example.addPerson("Ada");
	        example.addPerson("Alice");
	        example.addPerson("Bob");
	        example.printPeople("A");
	        example.close();
	    }
}

```

Here is where the debug stops, the program is "Values.java", the info is "Values:() line:85

```java
public abstract class Values
{
    public static final Value EmptyMap = value( Collections.emptyMap() );
    public static final Value NULL = NullValue.NULL;

```

Thank you.

---

<div class="post-metadata">

**Author:** ![jzhou002](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/jzhou002/32/16912_2.png) [@jzhou002](https://community.neo4j.com/u/jzhou002)\
**Post date:** [September 13, 2021, 4:21pm UTC](https://community.neo4j.com/t/java-driver-issue/44166/6 "2021-09-13T16:21:51Z")

</div>

I have neo4j-java-driver-4.3.4.jar and neo4j-jdbc-driver-3.4.0.jar in the build-path.

---

<div class="post-metadata">

**Author:** ![florent\_biville](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/florent_biville/32/14205_2.png) [@florent\_biville](https://community.neo4j.com/u/florent_biville)\
**Post date:** [September 13, 2021, 4:30pm UTC](https://community.neo4j.com/t/java-driver-issue/44166/7 "2021-09-13T16:30:13Z")

</div>

The code looks fine. Seems to be a connectivity issue with your local Neo4j server.  
How do you start it?

---

<div class="post-metadata">

**Author:** ![jzhou002](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/jzhou002/32/16912_2.png) [@jzhou002](https://community.neo4j.com/u/jzhou002)\
**Post date:** [September 13, 2021, 4:50pm UTC](https://community.neo4j.com/t/java-driver-issue/44166/8 "2021-09-13T16:50:31Z")

</div>

I started neo4jDesktop, then start the neo4j default database. From Chrom browser, I use [http://localhost](http://localhost)::7474/browser, it reads " You are connected as user `neo4j`to `neo4j://localhost:7687` Connection credentials are stored in your web browser." I use windows 10.

---

<div class="post-metadata">

**Author:** ![jzhou002](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/jzhou002/32/16912_2.png) [@jzhou002](https://community.neo4j.com/u/jzhou002)\
**Post date:** [September 13, 2021, 4:52pm UTC](https://community.neo4j.com/t/java-driver-issue/44166/9 "2021-09-13T16:52:14Z")

</div>

I open eclipse to bring up the java program, debug it, then th error message occurs as presented in previous posts.

---

<div class="post-metadata">

**Author:** ![jzhou002](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/jzhou002/32/16912_2.png) [@jzhou002](https://community.neo4j.com/u/jzhou002)\
**Post date:** [September 13, 2021, 5:46pm UTC](https://community.neo4j.com/t/java-driver-issue/44166/10 "2021-09-13T17:46:56Z")

</div>

python driver works perfectly, only jdbc driver not work.

---

<div class="post-metadata">

**Author:** ![florent\_biville](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/florent_biville/32/14205_2.png) [@florent\_biville](https://community.neo4j.com/u/florent_biville)\
**Post date:** [September 13, 2021, 6:02pm UTC](https://community.neo4j.com/t/java-driver-issue/44166/11 "2021-09-13T18:02:05Z")

</div>

You keep mentioning the JDBC driver, but the only code you have shown is from the Java Bolt driver, not the JDBC driver. Which one are you using:

- [GitHub - neo4j/neo4j-java-driver: Neo4j Bolt driver for Java](https://github.com/neo4j/neo4j-java-driver/) (Java Bolt driver)?
- [GitHub - neo4j-contrib/neo4j-jdbc: JDBC driver for Neo4j](https://github.com/neo4j-contrib/neo4j-jdbc) (JDBC driver)?

---

<div class="post-metadata">

**Author:** ![jzhou002](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/jzhou002/32/16912_2.png) [@jzhou002](https://community.neo4j.com/u/jzhou002)\
**Post date:** [September 13, 2021, 6:39pm UTC](https://community.neo4j.com/t/java-driver-issue/44166/12 "2021-09-13T18:39:00Z")

</div>

Ooops, I posted two the same examples. This is the different java I meant post .

```auto
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class neo4jjdbc {

	protected static Connection neoConnection() throws SQLException {
	    return DriverManager.getConnection("jdbc:neo4j:bolt://localhost:7687", "neo4j","password");
	}
	
	public static void main(String[] args) 
	{
		try
		{
			Connection connection = neoConnection();			
			connection.close();
		} catch (Exception e)
		{
			e.printStackTrace();
		}
	}
}

```

the error point to getConnection. Is this a jdbc example?

---

<div class="post-metadata">

**Author:** ![florent\_biville](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/florent_biville/32/14205_2.png) [@florent\_biville](https://community.neo4j.com/u/florent_biville)\
**Post date:** [September 13, 2021, 6:57pm UTC](https://community.neo4j.com/t/java-driver-issue/44166/13 "2021-09-13T18:57:43Z")

</div>

I assume you are using a 4.3.x Neo4j server in Neo4j Desktop (or at least a 4.x).  
If this is the case, you're using a JDBC driver that is too old.  
Please use a recent release like [Release 4.0.4 · neo4j-contrib/neo4j-jdbc · GitHub](https://github.com/neo4j-contrib/neo4j-jdbc/releases/tag/4.0.4) for instance.

---

<div class="post-metadata">

**Author:** ![jzhou002](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/jzhou002/32/16912_2.png) [@jzhou002](https://community.neo4j.com/u/jzhou002)\
**Post date:** [September 13, 2021, 9:16pm UTC](https://community.neo4j.com/t/java-driver-issue/44166/14 "2021-09-13T21:16:45Z")

</div>

That solves the issue, errors are gone. Now I try to manipulate data in neo4j. Thank you so very much for your patience and helps, really appreciate.

---

<div class="post-metadata">

**Author:** ![florent\_biville](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/florent_biville/32/14205_2.png) [@florent\_biville](https://community.neo4j.com/u/florent_biville)\
**Post date:** [September 14, 2021, 9:56am UTC](https://community.neo4j.com/t/java-driver-issue/44166/15 "2021-09-14T09:56:26Z")

</div>

Glad to read it worked out!
