orientDB使用

 OrientDB的java接口文档:

 
 

java API:


orientDB使用_第1张图片
 

1. 启动orientDB:

sh server.sh
 

2. 登录

http://localhost:2480/
账号: root
密码: CD081B7B8B229411A9AD414AE31547E5E4A087905FBD0302FC5736D0A1751239

orientDB使用_第2张图片
  
 

3. 添加maven依赖:

<!-- *** orientdb *** -->
		<dependency>
			<groupId>com.orientechnologies</groupId>
			<artifactId>orient-commons</artifactId>
			<version>1.6</version>
		</dependency>
		<dependency>
			<groupId>com.orientechnologies</groupId>
			<artifactId>orientdb-core</artifactId>
			<version>1.6</version>
		</dependency>
		<dependency>
			<groupId>com.orientechnologies</groupId>
			<artifactId>orientdb-graphdb</artifactId>
			<version>1.6</version>
			<exclusions>
				<exclusion>
					<groupId>com.tinkerpop.gremlin</groupId>
					<artifactId>gremlin-groovy</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>com.orientechnologies</groupId>
			<artifactId>orientdb-client</artifactId>
			<version>1.6</version>
		</dependency>

		<dependency>
			<groupId>com.tinkerpop</groupId>
			<artifactId>pipes</artifactId>
			<version>2.5.0</version>
		</dependency>
		<dependency>
			<groupId>com.tinkerpop.blueprints</groupId>
			<artifactId>blueprints-core</artifactId>
			<version>2.5.0</version>
		</dependency>
		<dependency>
			<groupId>com.tinkerpop.gremlin</groupId>
			<artifactId>gremlin-java</artifactId>
			<version>2.5.0</version>
		</dependency>
		<dependency>
			<groupId>com.tinkerpop.blueprints</groupId>
			<artifactId>blueprints-orient-graph</artifactId>
			<version>2.4.0</version>
		</dependency>


		<!-- *************** -->
 

4. 使用document API插入数据:

import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.record.impl.ODocument;

/**
 * 1⃣[Document API]<br>
 * 往orientDB里面,插入数据<br>
 * <a href="http://www.orientechnologies.com/docs/1.7.8/orientdb.wiki/Document-Database.html">http://www.orientechnologies.com/docs/1.7.8/orientdb.wiki/Document-Database.html</a>
 * <hr>
 * 》》安装:<br>
 * 下载http://www.orientechnologies.com/download/<br>
 * tar -zxvf orientdb-community-1.7.8.tar.gz<br>
 * <br>
 * <br>
 * 》》启动:<br>
 * sh server.sh<br>
 * <br>
 * <br>
 * 》》控制台:<br>
 * http://localhost:2480/ <br>
 * 
 * 
 * cd /Users/hyy044101331/java_tools/orientdb-community-1.7.8/config<br>
 * vi orientdb-server-config.xml<br>
 * 
 * 
 * <br>
 * user
 * password="CD081B7B8B229411A9AD414AE31547E5E4A087905FBD0302FC5736D0A1751239"
 * name="root”<br>
 * user resources="connect,server.listDatabases,server.dblist" password="guest"
 * name="guest"<br>
 * <br>
 * <ul>
 * <li>只读账号:"reader/reader”</li>
 * <li>写账号:"writer/writer”</li>
 * <li>admin账号:"admin/admin”</li>
 * </ul>
 * <br>
 * 》》数据库类型:<br>
 * <ul>
 *   <li>memory: means in-memory only database , 内存;</li>
 *   <li>plocal: embedded ones , 嵌入式;</li>
 *   <li>remote: use a remote database hosted on an up & running DBServer OrientDB Server instance , 远程;
 *      <br>例如:"remote:localhost/mengka"
 *   </li>
 * </ul>  
 * 
 * @author mengka.hyy
 * 
 */
public class orientdb_api_document01 {

	public static void main(String[] args) {

		/**
		 *  Document API
		 * 
		 *  ODatabaseDocumentTx是非线程安全的,所以在多线程使用的时候,需要初始化多个实例instances;
		 */
		String database = "remote:localhost/mengka";
		ODatabaseDocumentTx db = new ODatabaseDocumentTx(database).open(
				"admin", "admin");

		/**
		 * 例1: 插入第二行数据
		 * 
		 * 外键:City-北京
		 */
		ODocument out_bbDocument = new ODocument("City");
		out_bbDocument.field("name", "北京");
		out_bbDocument.field("country", "中国");
		ODocument bbDocument = new ODocument("Person");
		bbDocument.field("name", "蒙卡AAA");
		bbDocument.field("surname", "aaa..");
		bbDocument.field("city", out_bbDocument);
		bbDocument.save();

		/**
		 *  释放资源
		 */
		db.close();
	}
}
 

5. 查看数据:

select * from Person
 
orientDB使用_第3张图片
 

你可能感兴趣的:(IE)