Like RDBMS, OrientDB upholds JDBC. For this, first we need to design the climate for JDBC programming. Following is the strategy to make an association between your application and information base.
To begin with, we need to download the JDBC Driver. Visit the accompanying connection https://code.google.com/file/p/arrange/downloads to download OrientDB-JDBC.
Following are the essential five stages to accomplish OrientDB-jdbc network.
- Burden JDBC driver
- Make Connection
- Make proclamation
- Execute explanation
- Close association
Example
Attempt the accompanying guide to comprehend OrientDB-JDBC availability. Allow us to consider we have a worker table which contains the accompanying fields and its sorts.
Sr.No. | Field Name | Type |
---|---|---|
1 | Id | Integer |
2 | Name | String |
3 | Salary | Integer |
4 | Join date | Date |
You can make a Schema (table) by executing the accompanying orders.
CREATE DATABASE PLOCAL:/opt/orientdb/databases/testdb
CREATE CLASS Employee
CREATE PROPERTY Customer.id integer
CREATE PROPERTY Customer.name String
CREATE PROPERTY Customer.salary integer
CREATE PROPERTY Customer.join_date date
In the wake of executing all the orders, you will get the Employee table with the accompanying fields, worker name with id, age, and join_date fields.
Save the accompanying code into OrientJdbcDemo.java record.
import com.orientechnologies.common.log.OLogManager;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import java.io.File;
import java.sql.DriverManager;
import java.util.Properties;
import static com.orientechnologies.orient.jdbc.OrientDbCreationHelper.createSchemaDB;
import static com.orientechnologies.orient.jdbc.OrientDbCreationHelper.loadDB;
import static java.lang.Class.forName;
public abstract class OrientJdbcDemo {
protected OrientJdbcConnection conn;
public static void main(String ar[]){
//load Driver
forName(OrientJdbcDriver.class.getName());
String dbUrl = "memory:testdb";
ODatabaseDocumentTx db = new ODatabaseDocumentTx(dbUrl);
String username = "admin";
String password = "admin";
createSchemaDB(db);
loadDB(db, 20);
dbtx.create();
//Create Connection
Properties info = new Properties();
info.put("user", username);
info.put("password", password);
conn = (OrientJdbcConnection) DriverManager.getConnection("jdbc:orient:" + dbUrl, info);
//create and execute statement
Statement stmt = conn.createStatement();
int updated = stmt.executeUpdate("INSERT into emplyoee
(intKey, text, salary, date) values ('001','satish','25000','"
+ date.toString() + "')");
int updated = stmt.executeUpdate("INSERT into emplyoee
(intKey, text, salary, date) values ('002','krishna','25000','"
+ date.toString() + "')");
System.out.println("Records successfully inserted");
//Close Connection
if (conn != null && !conn.isClosed())
conn.close();
}
}
The accompanying order is utilized to aggregate the above program.
$ javac –classpath:.:orientdb-jdbc-1.0-SNAPSHOT.jar OrientJdbcDemo.java
$ java –classpath:.:orientdb-jdbc-1.0-SNAPSHOT.jar OrientJdbcDemo
In the event that the above order is executed effectively, you will get the accompanying yield.
Records Successfully Inserted