Can I Run only select query in memory option?


I Have to insert my data into database using remote mode.And only while using select query I have to run it in memory mode.Is that Possible in orientdb?Any Help would be greatly appreciated.


Hi @Harish

OrientDB has a built-in memory cache that tends to keep as much data as possible in RAM (off-heap), even the full DB if it has enough memory. You don’t have to do anything particular, it just happens out of the box




Hi @luigidellaquila
Sorry for the less information. My orient db and Java Application are in Same servers. I have a java code which inserts a bulk data into the database. While inserting data i am using remote mode to connect the database. While retrieving data from database using select query I have to use memory or plocal mode to connect the database.Is that possible?If so suggest an example to connect the database in plocal or memory mode. I have given java code for reference that i am using for insertion and retrieving data form db. while i am trying to connect with memory mode i am getting the following error

com.orientechnologies.orient.core.exception.OStorageException: Cannot open local storage ‘/root/orientdb-3.0.10/databases/demodb’ with mode=rw

Insertion Code

	public static Response orientDBInsertion(String query, String className) throws SQLException
		Response response = new Response();
		Connection connection = null;
		{"**Before Connection**");
  	**connection = (OrientJdbcConnection) DriverManager.getConnection("jdbc:orient:remote:<url>/demodb", "admin","admin");**"**Connection estabilshed**");
			Statement statement = connection.createStatement();"**Query**> " + query);
			int result = statement.executeUpdate(query);
			if (result > 0)
				ResultSet resultSet1 = statement.executeQuery("select max(@rid) as rid FROM " + className + ";");
				String rid = resultSet1.getString("rid");
				JSONObject toRet = new JSONObject();

				toRet.put("rid", rid.split("#")[1].split("\\{")[0]);
			} else
				response.setData("Insertion failed");

		} catch (Exception e)
			logger.error("Exception in Orient Query Insertion Execution : " + e);
		} finally
		return response;

Java Code for executing Select Query

> 	public static String SelectqueryExecution(String query1) throws SQLException, ClassNotFoundException
> 	{
> 			LinkedHashSet<LinkedHashMap<String, String>> toRet = new LinkedHashSet<>();
> 			StringBuilder sb = new StringBuilder();
> 			OrientGraphFactory factory = null;
> 			try
> 			{
> 				long startTime = System.currentTimeMillis();
> 				System.out.println("***********Before Connection**********");
> 				**factory = new OrientGraphFactory("memory:<Path>/demodb/", "admin", "admin");**
> 				factory.declareIntent(new OIntentMassiveInsert());
> 				OObjectDatabaseTx database = new OObjectDatabaseTx("memory:<Path>/demodb").open("admin", "admin");
> 				System.out.println("***********Connection estabilshed**********");
> 				System.out.println("dataBase OPened");
> 				OResultSet result = database.command(query1);
> 				String key[]=null;
> 				System.out.println(result.estimateSize());
> 				while(result.hasNext())
> 				{
> 					LinkedHashMap<String, String> linkedObj = new LinkedHashMap<>();
> 					OResult result1 =;
> 					key=result1.getPropertyNames().toString().replaceAll("\\[", "").replaceAll("\\]", "").split("\\,");
> 					System.out.println(result1.getPropertyNames().size());
> 					for(int i=0;i<result1.getPropertyNames().size();i++)
> 					{
> 						linkedObj.put(key[i].trim().toString(), result1.getProperty(key[i].trim()).toString());
> 					}
> 					if (linkedObj.size() > 0)
> 					{
> 						toRet.add(linkedObj);
> 					}
> 				}
> 				try
> 				{
> 					String resultJson = new ObjectMapper().writeValueAsString(toRet);
> 					//System.out.println("******************************* " + resultJson);
> 					sb.append(resultJson);
> 					return resultJson;
> 				} catch (JsonProcessingException e)
> 				{
> 					//logger.error("JsonProcessingException : " + e);
> 				}	
> 				System.out.println("Time Taken to create vertex and edges " + (System.currentTimeMillis() - startTime));
> 			} catch (Exception e)
> 			{
> 				System.out.println("Exception in Loading data : " + e);
> 				e.printStackTrace();
> 			}
> 			finally
> 			{
> 				if (factory.exists())
> 				{
> 					factory.close();
> 				}
> 				System.out.println(sb.toString());
> 				return sb.toString();
> 			}
> 	}


Hi @Harish

Ok, now I got the point.
You cannot access the same DB from two different JVMs, ie. if you have a running OrientDB server (with clients connecting from remote) you cannot launch another Java process on the same databases in plocal.

The solution is to have an embedded server that does the plocal/memory operations and then have the clients connect to it in remote. You can find a guide here




Hi @luigidellaquila

Thanks for the reply. I have a database already created in orientdb. Now while embedding the server new database is created inside my java application. I need to replicate the existing database with same data in my java application and also if any changes happens in the existing database, Will that change will reflect in embedded db?. Can you please suggest some example?.And coming to performance, will it really help me in case of bulk load and retrieval?