java连接neo4j——jdbc

jar包:neo4j-jdbc-2.0.1-SNAPSHOT-jar-with-dependencies.jar

package neo4j;

import java.sql.*;

/**
 * @Author: Yilia
 * @Date: 2021/12/16/0016 15:12
 */

public class JDBCConnect {
    public static void main(String[] args) {
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;

        try {
            // 填写自己设置的用户名密码
            connection = DriverManager.getConnection("jdbc:neo4j://localhost:7474/", "username", "password");
            //采用预编译,和关系数据库不一样的是,参数需要使用{1},{2},而不是?
            String query = "match (n:Person) where n.name is not null return n.name as name";
            preparedStatement = connection.prepareStatement(query);
            resultSet = preparedStatement.executeQuery();
            while (resultSet.next()) {
                System.out.printf( "%s=%s%n", "name", resultSet.getString("name"));
            }
        } catch (SQLException sqlException) {
            sqlException.printStackTrace();
        } finally {
            try {
                if (null != resultSet) {
                    resultSet.close();
                }
                if (null != preparedStatement) {
                    preparedStatement.close();
                }
                if (null != connection) {
                    connection.close();
                }
            } catch (SQLException sqlException) {
                sqlException.printStackTrace();
            }
        }
    }
}

java连接neo4j——jdbc_第1张图片

缺点:

  1. 不支持关系之间权重计算;

你可能感兴趣的:(知识图谱,图形数据库,java,开发语言,后端)