ArangoDB入门教程(四)java操作ArangoDB数据库

废话不多说,代码如下:

   

                    Github地址:https://github.com/yongzhuo/JavaLearning/tree/master/src/java/JavaToArangodb

import com.arangodb.ArangoCursor;
import com.arangodb.ArangoDB;
import com.arangodb.ArangoDatabase;
import com.arangodb.ArangoCollection;
import com.arangodb.internal.ArangoCursorIterator;
import com.arangodb.model.AqlQueryOptions;
import com.arangodb.util.MapBuilder;
import org.bson.Document;
import org.junit.Test;

import java.io.File;
import java.util.*;
public class  ArangoTest{
@Test
public void findrole() throws Exception{
    try {
        ArangoDB arango = new ArangoDB.Builder().host("127.0.0.1", 8529).user("root").password("root").build();
        ArangoDatabase mydb = arango.db("myAQL");


        String queryCmmd = "for doc in @@collection return  doc";
        AqlQueryOptions options = new AqlQueryOptions();
        options.ttl(1000000);//持续时间
        Map map =new HashMap();
        map.put("@collection","test");
        ArangoCursor cursor = mydb.query(queryCmmd, map, options, BaseDocument.class);
        int ii = 0;
        while (cursor.hasNext()) {
            ii++;
            BaseDocument object = cursor.next();
       //String name =object.getAttribute("name").toString();     //输出  
	       System.out.println(object.toString());           
	       System.out.println(ii);    
    }    
	}catch (Exception e){
	e.printStackTrace();
	}
	}
	}

 

 

 

你可能感兴趣的:(ArangoDB,知识图谱)