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()
:
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) throws InterruptedException {
UltipaConfig ultipaConfig = UltipaConfig.config()
// URI example: .hosts(Lists.newArrayList("https://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);
} finally {
if (driver != null) {
driver.close();
}
}
}
}
Connection succeeds: true
UltipaConfig Attributes
The UltipaConfig
class includes the following attributes:
Attribute |
Type |
Default |
Description |
---|---|---|---|
hosts |
List<String> | / | Required. A comma-separated list of database server IPs or URLs. If a URL does not start with https:// or http:// , http:// is prefixed by default. |
username |
String | / | Required. Username of the host authentication. |
password |
String | / | Required. Password of the host authentication. |
defaultGraph |
String | / | Name of the graph to use by default in the database. |
crt |
String | / | The file path of the SSL certificate used for secure connections. |
passwordEncrypt |
String | MD5 |
Password encryption method of the driver. Supports MD5 , LDAP and NOTHING . |
timeout |
Integer | 15 | Connection timeout threshold (in second). |
heartBeat |
Integer | 0 | The heartbeat interval (in millisecond), used to keep the connection alive. Set to 0 to disable. |
maxRecvSize |
Integer | 32 | The maximum size (in MB) of the received data. |
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 |
---|---|---|---|
maxTotal |
int | 8 | Maximum number of total connections (active + idle) allowed in the pool. |
maxIdle |
int | 8 | Maximum number of idle connections in the pool. |
minIdle |
int | 1 | Minimum number of idle connections to maintain. |
minEvictableIdleTimeMillis |
long | 1800000L (30 minutes) | Minimum time a connection may sit idle before being eligible for eviction. |
timeBetweenEvictionRunsMillis |
long | 600000L (10 minutes) | Time interval between eviction runs that check idle connections. |
numTestsPerEvictionRun |
int | 3 | Number of connections to test during each eviction run. |
testOnBorrow |
boolean | false | Whether to validate a connection before borrowing from the pool. |
testOnReturn |
boolean | true | Whether to validate a connection when returning it to the pool. |
testWhileIdle |
boolean | true | Whether to validate idle connections during eviction runs. |
maxWaitMillis |
long | -1L | Maximum time to wait for a connection when the pool is exhausted (-1 = wait indefinitely). |
lifo |
boolean | true | Whether to use LIFO (last-in-first-out) order for connection retrieval. |
blockWhenExhausted |
boolean | true | Whether to block when the pool is exhausted or immediately throw an exception. |
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) throws InterruptedException {
UltipaConfig ultipaConfig = UltipaConfig.config()
// URI example: .hosts(Lists.newArrayList("https://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);
} finally {
if (driver != null) {
driver.close();
}
}
}
}
Connection succeeds: true