The Java SDK for YDB enables Java developers to work with YDB.
Before you begin, you need to create a database and setup authorization. Please see the Prerequisites section of the connection guide in documentation for information on how to do that.
To use YDB Java SDK you will need Java 1.8+.
The recommended way to use the YDB Java SDK in your project is to consume it from Maven. Firstly you can import YDB Java BOM to specify correct versions of SDK modules.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>tech.ydb</groupId>
<artifactId>ydb-sdk-bom</artifactId>
<version>2.5.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>After that you can specify the SDK modules that your project needs in the dependencies:
<dependencies>
<!-- Scheme service client -->
<dependency>
<groupId>tech.ydb</groupId>
<artifactId>ydb-sdk-scheme</artifactId>
</dependency>
<!-- Table service client -->
<dependency>
<groupId>tech.ydb</groupId>
<artifactId>ydb-sdk-table</artifactId>
</dependency>
<!-- Query service client -->
<dependency>
<groupId>tech.ydb</groupId>
<artifactId>ydb-sdk-query</artifactId>
</dependency>
<!-- Topic service client -->
<dependency>
<groupId>tech.ydb</groupId>
<artifactId>ydb-sdk-topic</artifactId>
</dependency>
<!-- Coordination service client -->
<dependency>
<groupId>tech.ydb</groupId>
<artifactId>ydb-sdk-coordination</artifactId>
</dependency>
</dependencies>Enable PRIMARY/PROMOTED pile preference explicitly when building the transport:
GrpcTransport transport = GrpcTransport.forConnectionString(connectionString)
.withBalancingSettings(BalancingSettings.preferPrimaryPile())
.build();Use tech.ydb.core.grpc.BalancingSettings and tech.ydb.core.grpc.GrpcTransport.
The policy follows pile roles reported by discovery, including role changes at unchanged endpoint addresses.
SYNCHRONIZED endpoints remain available as fallback; other or unknown states are last-resort candidates.
On a cluster without Bridge metadata the policy uses ordinary balancing. The default policy is unchanged.
Requests bound to an existing session or a specific node retain their node affinity.
YDB Java SDK comply to guidelines from SemVer2.0.0 with several exceptions.
In basic example folder there is simple example application that uses YDB Java SDK from Maven. See the Connect to a database section of the documentation for an instruction on how to setup and launch it.
In examples folder you can find more example applications with YDB Java SDK usage.
To build the YDB Java SDK artifacts locally, see Building YDB Java SDK.