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.
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:
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 -- 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?
Hi Adreas, thanks for the reply. I run neo4j locally, I can use Chrome to connect to neo4j 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.
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
This is also from neo4j example, it uses "bolt://localhost", and error point to the uri
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
public abstract class Values
{
public static final Value EmptyMap = value( Collections.emptyMap() );
public static final Value NULL = NullValue.NULL;
I started neo4jDesktop, then start the neo4j default database. From Chrom browser, I use http://localhost::7474/browser, it reads " You are connected as user neo4jto neo4j://localhost:7687 Connection credentials are stored in your web browser." I use windows 10.
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 for instance.