AgensGraph JDBC driver 是 AgensGraph 图数据库官方的开源 JDBC 驱动程序。
示例代码:
import java.sql.DriverManager; import java.sql.Connection; public class AgensGraphTest { public static void main(String[] args) { Class.forName("net.bitnine.agensgraph.Driver"); String connectionString = "jdbc:agensgraph://127.0.0.1:5432/agens"; String username = "test"; String password = "test"; Connection conn = DriverManager.getConnection(connectionString, username, password); //创建对象 PreparedStatement pstmt = con.prepareStatement("CREATE (:Person ?)"); JsonObject john = new JsonObject(); john.put("name", "John"); john.put("from", "USA"); john.put("age", 17); pstmt.setObject(1, john); pstmt.execute(); //查询 Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery( "MATCH (:Person {name: 'John'})-[:knows]-(friend:Person)" + "RETURN friend"); while (rs.next()) { Vertex friend = (Vertex)rs.getObject(1); System.out.println(friend.getProperty().getString("name")); System.out.println(friend.getProperty().getInt("age")); } } }
Maven:
<dependency> <groupId>net.bitnine</groupId> <artifactId>agensgraph-jdbc</artifactId> <version>1.2.0</version> </dependency>