neo4j 3.4.9 客户端连接方式

jdk 1.8, pom.xml中主要引用是:

        <dependency>
            <groupId>org.neo4j</groupId>
            <artifactId>neo4j-jdbc-driver</artifactId>
            <version>3.4.0</version>
        </dependency>
单元测试类是:

public class ContactsTest {


  @Test
  public void testBolt() throws Exception {
    String boltUri = "bolt://localhost:7687";
    String user = "neo4j";
    String password = "xxxx";
    Driver driver = GraphDatabase.driver(boltUri, AuthTokens.basic(user, password));;
    // Connect 10.1.1.29   
    // Querying
    try (Session session = driver.session()) {
      String stmt = session.readTransaction(new TransactionWork<String>() {
        @Override
        public String execute(Transaction tx) {
          StatementResult result = tx.run("MATCH (n:contact) RETURN n.USER_NAME limit 10");
          List<Record> list=result.list();
          System.out.println("结果:"+list.size());
          return list.get(0).toString();
        }
      });
      System.out.println("结果:"+stmt);
    }
  }

  @Test
  public void testJdbc() throws Exception {
    
     Class.forName("org.neo4j.jdbc.Driver").newInstance();
    // Connect 10.1.1.29  
     Neo4jConnection con = (Neo4jConnection) DriverManager.getConnection("jdbc:neo4j:http://localhost:7474", "neo4j", "xxxxx");
    // Querying
    try (Statement stmt = con.createStatement()) {
      ResultSet rs = stmt.executeQuery("MATCH (n:contact) RETURN n.USER_NAME  limit 10");
      while (rs.next()) {
        System.out.println(rs.getString("n.USER_NAME"));
      }
    }
    con.close();
  }


}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值