java连接neo4j之jdbc


neo4j连接java目前主要有嵌入式、jdbc和rest api。

jdbc:需要使用到的lib包:neo4j-jdbc-2.0.1-SNAPSHOT-jar-with-dependencies.jar

Connection con = DriverManager
                .getConnection("jdbc:neo4j://localhost:7474/");  //创建连接

        String query = "start n = node({1}) return n.name";

        PreparedStatement stmt = null;       //采用预编译,和关系数据库不一样的是,参数需要使用{1},{2},而不是?
        ResultSet rs = null;
        try {
            stmt = con.prepareStatement(query);
            stmt.setInt(1, 14);
            rs = stmt.executeQuery();
            System.out.println(rs.getRow());
            while (rs.next()) {
                System.out.println("a " + rs.getString("n.name"));
            }
        } catch (Exception e) {
            throw e;
        } finally {
            if (null != rs) {
                rs.close();
            }
            if (null != stmt) {
                stmt.close();
            }
        }

jdbc连接的是服务式neo4j。

目前cypher语言提供的shorestPath方法仅仅支持计算两个节点间经过的节点数最小的路径,不支持关系之间的权重计算,如果需要计算权重的最短路径,则需要使用内嵌式,或者是服务式的rest API。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM