Skip to content

Instantly share code, notes, and snippets.

Created Nov 8, 2016
What would you like to do?
Using [Neo4j's JDBC Driver]( with [JDBI]( also for [DropWizard](
install and start Neo4j from
start the Neo4j Desktop or $NEO4J_HOME/bin/neo4j start
$GROOVY_HOME/bin/groovy neo4j-jdbi.groovy
The Matrix
The Matrix
// Code from the JDBI Getting Started Page:
// JDBI API Docs:
// neo4j-jdbc-driver:
[@Grab(group='org.jdbi', module='jdbi', version='2.77'),
@Grab(group='org.neo4j', module='neo4j-jdbc-driver', version='3.0.1')]
import org.skife.jdbi.v2.*
import org.skife.jdbi.v2.sqlobject.*
import org.skife.jdbi.v2.util.*
DBI dbi = new DBI("jdbc:neo4j:bolt://localhost","neo4j","test");
// dbi.setStatementRewriter(new NoOpStatementRewriter());
dbi.setStatementRewriter(new HashPrefixStatementRewriter());
Handle h =;
h.execute("create index on :Movie(title)");
h.execute("create (m:Movie) SET = #id, = #name", 1, "The Matrix");
String name = h.createQuery("MATCH (m:Movie) WHERE = #id RETURN as name")
.bind("id", 1)
assert name == "The Matrix";
String name3 = h.createQuery("MATCH (m:Movie) WHERE = {1} RETURN as name")
.bind(0, 1)
public interface PersonDAO
@SqlUpdate("create index on :Person(name)")
void createIndex();
@SqlUpdate("merge (p:Person {id: #id}) ON CREATE SET")
void insert(@Bind("id") int id, @Bind("name") String name);
@SqlQuery("match (p:Person) where = #id return as name")
String findNameById(@Bind("id") int id);
* close with no args is used to close the connection
void close();
PersonDAO dao =;
dao.insert(2, "Neo");
String name2 = dao.findNameById(2);
assert name2 == "Neo";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment