How to set up jdbc connection with neo4j?

I understand that while jdbc is usually used for SQL queries, since the SQL query is essentially just a string, JDBC is not going to know if it is an SQL query or a cypher query.

From what I can see, I just need to import the neo4j jdbc driver and use it to pass my cypher request to the neo4j database.

pom.xml

    <dependency>
        <groupId>org.neo4j</groupId>
        <artifactId>neo4j-jdbc</artifactId>
        <version>2.1.4</version>
        <type>pom</type>
    </dependency>

      

Now I am trying something like this:

    this.dataSource = new DriverManagerDataSource(this.DBURL,this.USERNAME, this.PASSWORD);


    this.dataSource.setDriverClassName("org.neo4j.jdbc.Driver");        
    this.jdbcTemplate  = new JdbcTemplate(this.dataSource); 

    String qq = "MATCH (n:Individual) RETURN n LIMIT 25;";      
    Map<String,Object> res = jdbcTemplate.queryForMap(qq); //I actually just want to return a JSON string, but this is the only example I can find for now

      

This code will give me:

java.lang.ClassNotFoundException: org.neo4j.jdbc.Driver
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:274)
    at org.springframework.jdbc.datasource.DriverManagerDataSource.setDriverClassName(DriverManagerDataSource.java:127)

      

What am I doing wrong here? What's the correct driver class name?

I have also tried

Class.forName("org.neo4j.jdbc.Driver");

      

and I get:

java.lang.ClassNotFoundException: org.neo4j.jdbc.Driver
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:191) 

      

+3


source to share


2 answers


Usually you need to execute first Class.forName("org.neo4j.jdbc.Driver")

to load the driver class.

What does your JDBC URL look like?



Note that the JDBC driver (in the remote case) will return Map

with the data of each node.

-1


source


try to change Class.forName("org.neo4j.jdbc.Driver")

about



Class.forName("org.neo4j.jdbc.Driver").newInstance()

-1


source







All Articles