Skip to content

Instantly share code, notes, and snippets.

@Judit
Last active August 29, 2015 13:57
Show Gist options
  • Save Judit/9742110 to your computer and use it in GitHub Desktop.
Save Judit/9742110 to your computer and use it in GitHub Desktop.
Neo4j JDBC - Connect with GrapheneDB
import org.neo4j.jdbc.Driver;
import org.neo4j.jdbc.Neo4jConnection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
public class HelloWorld {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
final Driver driver = new Driver();
final String hostPort = REST_URL;
final String query = "START root=node(0) RETURN root";
final Properties props = new Properties();
props.put("user", USER);
props.put("password", PASSWORD);
Neo4jConnection conn = driver.connect("jdbc:neo4j://" + hostPort, props);
ResultSet rs = conn.createStatement().executeQuery(query);
rs.next();
System.out.println(rs.toString());
}
}
import org.neo4j.jdbc.Driver;
import org.neo4j.jdbc.Neo4jConnection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
public class HelloWorld {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
final Driver driver = new Driver();
final String hostPort = REST_URL;
final String query = "CREATE (n {name:'helloNode'}) RETURN 'helloNode', n.name";
final Properties props = new Properties();
props.put("user", USER);
props.put("password", PASSWORD);
props.put("legacy", ""); // Need to work with Neo4j Community Edition 2.0.1
Neo4jConnection conn = driver.connect("jdbc:neo4j://" + hostPort, props);
ResultSet rs = conn.createStatement().executeQuery(query);
rs.next();
System.out.println(rs.toString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment