1.maven中添加
<dependency>
<groupId>com.vesoft</groupId>
<artifactId>client</artifactId>
<version>3.6.0</version>
</dependency>
2.编写驱动类
public Object nebulaJdbcDriver(String execStr) {
List<HostAddress> addresses = Collections.singletonList(new HostAddress("nebula的IP", 9669));
String spaceName = "空间名";
String user = "nebula";//账号
String password = "nebula";//密码
SessionPoolConfig sessionPoolConfig = new SessionPoolConfig(addresses, spaceName, user,password);
SessionPool sessionPool = new SessionPool(sessionPoolConfig);
if (!sessionPool.init()) {
return "error";
}
ResultSet resultSet = null;
try {
resultSet = sessionPool.execute(execStr);
System.out.println(resultSet.toString());
} catch (IOErrorException | ClientServerIncompatibleException | AuthFailedException | BindSpaceFailedException e) {
e.printStackTrace();
sessionPool.close();
System.exit(1);
}
sessionPool.close();
return resultSet.toString();
}
3.项目中调用
@GetMapping("/getNebula")
public Object getNebula() {
String execStr = "match (v:player) return v limit 1;";
Object resultSet = new NebulaDriver().nebulaJdbcDriver(execStr);
return resultSet.toString();
}