Skip to content

Instantly share code, notes, and snippets.

@michael-simons
Last active July 9, 2025 15:12
Show Gist options
  • Save michael-simons/665281b93658b953917974bb693dadea to your computer and use it in GitHub Desktop.
Save michael-simons/665281b93658b953917974bb693dadea to your computer and use it in GitHub Desktop.
import module java.sql;
import module org.neo4j.jdbc;
// java --enable-preview --module-path neo4j-jdbc-full-bundle-6.7.0.jar --add-modules org.neo4j.jdbc Demo1.java
void main() throws SQLException {
try (
var connection = DriverManager.getConnection("jdbc:neo4j://localhost:7687/movies?enableSQLTranslation=true", "neo4j", "verysecret");
var stmt = connection.prepareStatement("""
INSERT INTO Movie (title, released) VALUES (?, ?)
ON CONFLICT DO NOTHING
"""))
{
stmt.setString(1, "Dune");
stmt.setInt(2, 2021);
stmt.addBatch();
stmt.setString(1, "Star Trek Generations");
stmt.setInt(2, 1994);
stmt.addBatch();
stmt.setString(1, "Seven");
stmt.setInt(2, 1995);
stmt.addBatch();
stmt.executeBatch();
}
try (
var connection = DriverManager.getConnection("jdbc:neo4j://localhost:7687/movies", "neo4j", "verysecret");
var stmt = connection.prepareStatement("""
MATCH (n:$($label))
WHERE n.released = $year
RETURN DISTINCT n.title AS title""")
.unwrap(Neo4jPreparedStatement.class))
{
stmt.setString("label", "Movie");
stmt.setInt("year", 1995);
var rs = stmt.executeQuery();
while (rs.next()) {
var title = rs.getString("title");
System.out.println(title);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment