JDBC方式 访问 图数据库 OrientDB

友情提示:图数据库 OrientDB 安装 及 初步使用

目录

    • 额外的Jar包
    • 测试

额外的Jar包

  • 上官网下载 OrientDB JDBC 驱动

https://orientdb.com/download-2/,单击此链接,如下图所示
JDBC方式 访问 图数据库 OrientDB_第1张图片
下载矩形方框中的驱动即可。

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


com.orientechnologies
orientdb-client
3.0.6

但这种方式,笔者尝试过,会报错,还需要添加其他依赖。

测试

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

你可能感兴趣的:(图)