JDBC方式 访问 图数据库 OrientDB

2022-04-08 00:00:00 专区 订阅 付费 所示 额外

目录
额外的Jar包
测试
额外的Jar包
上官网下载 OrientDB JDBC 驱动
https://orientdb.com/download-2/,单击此链接,如下图所示


下载矩形方框中的驱动即可。

当然,官方也说了可以通过Maven来管理依赖,如下所示

<dependency>
<groupId>com.orientechnologies</groupId>
<artifactId>orientdb-client</artifactId>
<version>3.0.6</version>
</dependency>
1
2
3
4
5
但这种方式,笔者尝试过,会报错,还需要添加其他依赖。

测试
import com.orientechnologies.orient.jdbc.OrientJdbcConnection;

import java.sql.*;
import java.util.Properties;

/**
* Created by Administrator on 2018/8/12 20:59 in Beijing.
*/

public class OrientDBJdbc {
public static void main(String[] args) throws SQLException {
/* declare admin credentials */
Properties properties = new Properties();
properties.put("user", "root");
properties.put("password", "root");

/* obtain a connection */
Connection conn = (OrientJdbcConnection) DriverManager.getConnection("jdbc:orient:remote:localhost/graphdb", properties);

/* perform a query */
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * from V");

/* consume the resultset */
while (rs.next()) {
int vertexVersion = rs.getInt("@version");
String vertexName = rs.getString("name");
String vertexClass = rs.getString("@class");
System.out.println("version=" + vertexVersion + ", name=" + vertexName + ", class=" + vertexClass);
}

rs.close();
stmt.close();
conn.close();
}
}
输出

version=14, name=Bob, class=Vgraphx
version=5, name=David, class=Vgraphx
version=14, name=Charlie, class=Vgraphx
version=6, name=Esther, class=Vgraphx
version=5, name=Fanny, class=Vgraphx
version=3, name=Gabby, class=Vgraphx
version=8, name=Alice, class=Vgraphx

相关文章