Skip to content

Instantly share code, notes, and snippets.

@Leward
Created July 16, 2015 11:26
Show Gist options
  • Save Leward/7386a1a4f62e0ce45b76 to your computer and use it in GitHub Desktop.
Save Leward/7386a1a4f62e0ce45b76 to your computer and use it in GitHub Desktop.
Load articles titles in DB
// Put the article titles into a database
Class.forName("org.neo4j.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:neo4j://localhost:7474/");
titles.each {
def cypherQuery = """
MERGE (w:Website {name: {1}})
MERGE (d:Day {date: {2}})
CREATE
(a:Article {3}),
(a)-[:PUBLISHED_ON]->(w),
(a)-[:PUBLISHED_AT]->(d)
"""
def stmt = con.prepareStatement(cypherQuery)
stmt.setString(1, "slate.com")
stmt.setString(2, new Date().format("YYYY/MM/dd"))
stmt.setObject(3, [title: it])
stmt.executeUpdate()
println "Inserted: ${it}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment