UltipaDocs
Try Playground
  • Introduction
    • Installation
    • Connection
      • Overview and Request Configuration
      • UQL Execution
      • GQL Execution
      • Graph
      • Schema and Property
      • Data Insertion
      • Query Acceleration
      • HDC Graph and Algorithm
      • Data Export
      • Process and Job
      • Access Control
    • Result Processing
    • Driver Data Classes
    • Installation
    • Connection
      • Overview and Request Configuration
      • UQL Execution
      • GQL Execution
      • Graph
      • Schema and Property
      • Data Insertion
      • Query Acceleration
      • HDC Graph and Algorithm
      • Data Export
      • Process and Job
      • Access Control
    • Result Processing
    • Driver Data Classes
    • Quick Start
    • Connect to Database
    • Query the Database
      • Graph
      • Schema and Property
      • Data Insertion
      • Query Acceleration
      • HDC Graph and Algorithm
      • Data Export
      • Process and Job
      • Access Control
    • Process Query Results
    • Data Structures
    • Quick Start
    • Connect to Database
    • Query the Database
      • Graph
      • Schema and Property
      • Data Insertion
      • Query Acceleration
      • HDC Graph and Algorithm
      • Data Export
      • Process and Job
      • Access Control
    • Process Query Results
    • Data Structures
    • Installation
    • Connection
    • Request Configuration
    • UQL Execution
    • GQL Execution
    • Graphset Management
    • Schema and Property Management
    • Data Insertion and Deletion
    • Query Acceleration
    • Algorithm Management
    • Downloads and Exports
    • Process and Task Management
    • Access Management
    • Server Statistics
    • Result Processing
    • Types Mapping Ultipa and C#
  • RESTful API
  1. Docs
  2. /
  3. Ultipa Drivers
  4. /
  5. Java

Connection

Once you have installed the driver and set up an Ultipa instance, you can connect your application to the database.

You can establish a connection using the configurations from UltipaConfig. See UltipaConfig Attributes.

Creating a Connection

Creates a connection using UltipaDriver():

Main.java
package com.ultipa.www.sdk.api;

import com.ultipa.sdk.UltipaDriver;
import com.ultipa.sdk.connect.conf.UltipaConfig;
import org.assertj.core.util.Lists;

public class Main {
    public static void main(String[] args) {
        UltipaConfig ultipaConfig = UltipaConfig.config()
                // URI example: .hosts(Lists.newArrayList("d3026ac361964633986849ec43b84877s.eu-south-1.cloud.ultipa.com:8443"))
                .hosts(Lists.newArrayList("192.168.1.85:60061","192.168.1.88:60061","192.168.1.87:60061"))
                .username("<username>")
                .password("<password>");

        UltipaDriver driver = null;

        try {
            driver = new UltipaDriver(ultipaConfig);
            Boolean isSuccess = driver.test();
            System.out.println("Connection succeeds: " + isSuccess);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } finally {
            if (driver != null) {
                driver.close();
            }
        }
    }
}
Output
Connection succeeds: true

UltipaConfig Attributes

The UltipaConfig class includes the following attributes:

Attribute
Type
Default
Description
hostsList<String>/Required. A comma-separated list of database server IPs or URLs. The protocol is automatically identified, do not include https:// or http:// as a prefix in the URL.
usernameString/Required. Username of the host authentication.
passwordString/Required. Password of the host authentication.
defaultGraphString/Name of the graph to use by default in the database.
crtString/The file path of the SSL certificate used for secure connections.
passwordEncryptStringMD5Password encryption method of the driver. Supports MD5, LDAP and NOTHING.
connectTimeoutInteger2000Connection timeout threshold (in milliseconds). By default, each host is attempted three times.
timeoutIntegerMaximumRequest timeout threshold (in second).
heartbeatInteger0The heartbeat interval (in millisecond), used to keep the connection alive. Set to 0 to disable.
maxRecvSizeInteger32The maximum size (in MB) of the received data.
poolConfigPoolConfig/Configures Connection Pooling.
keepAliveInteger120The maximum period (in seconds) of inactivity before sending a keep-alive probe to the host to maintain connection responsiveness (may increase service load).
keepAliveWithoutCallsBooleanfalseActivates keep-alive mechanism even during connection inactivity.
overrideAuthorityString/Overrides hostname with ultipa to match server certificate authority.

Connection Pooling

Ultipa.poolConfig contains the configuration for using the Apache Commons Pool library. These settings are necessary when connecting to a database to efficiently handle and reuse connections.

The PoolConfig class includes the following attributes:

Attribute
Type
Default
Description
maxTotalint8Maximum number of total connections (active + idle) allowed in the pool.
maxIdleint8Maximum number of idle connections in the pool.
minIdleint1Minimum number of idle connections to maintain.
minEvictableIdleTimeMillislong1800000L (30 minutes)Minimum time a connection may sit idle before being eligible for eviction.
timeBetweenEvictionRunsMillislong600000L (10 minutes)Time interval between eviction runs that check idle connections.
numTestsPerEvictionRunint3Number of connections to test during each eviction run.
testOnBorrowbooleanfalseWhether to validate a connection before borrowing from the pool.
testOnReturnbooleantrueWhether to validate a connection when returning it to the pool.
testWhileIdlebooleantrueWhether to validate idle connections during eviction runs.
maxWaitMillislong-1LMaximum time to wait for a connection when the pool is exhausted (wait indefinitely by default).
lifobooleantrueWhether to use LIFO (last-in-first-out) order for connection retrieval.
blockWhenExhaustedbooleantrueWhether to block when the pool is exhausted or immediately throw an exception.
Main.java
package com.ultipa.www.sdk.api;

import com.ultipa.sdk.UltipaDriver;
import com.ultipa.sdk.connect.conf.PoolConfig;
import com.ultipa.sdk.connect.conf.UltipaConfig;
import org.assertj.core.util.Lists;

public class Main {
    public static void main(String[] args) {
        UltipaConfig ultipaConfig = UltipaConfig.config()
                // URI example: .hosts(Lists.newArrayList("d3026ac361964633986849ec43b84877s.eu-south-1.cloud.ultipa.com:8443"))
                .hosts(Lists.newArrayList("192.168.1.85:60061","192.168.1.88:60061","192.168.1.87:60061"))
                .username("<username>")
                .password("<password>");

        PoolConfig poolConfig = ultipaConfig.getPoolConfig();
        poolConfig.setMaxIdle(50);
        poolConfig.setMinIdle(2);
        poolConfig.setMaxTotal(200);

        UltipaDriver driver = null;

        try {
            driver = new UltipaDriver(ultipaConfig);
            Boolean isSuccess = driver.test();
            System.out.println("Connection succeeds: " + isSuccess);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } finally {
            if (driver != null) {
                driver.close();
            }
        }
    }
}
Output
Connection succeeds: true