YugaByte SQL JDBC Driver - JDBC 4.2

Java JDBC 4.2 (JRE 8+) driver for YugaByte SQL database

License

License

GroupId

GroupId

com.yugabyte
ArtifactId

ArtifactId

ysql
Last Version

Last Version

42.2.7-yb-2
Release Date

Release Date

Type

Type

jar
Description

Description

YugaByte SQL JDBC Driver - JDBC 4.2
Java JDBC 4.2 (JRE 8+) driver for YugaByte SQL database
Project URL

Project URL

https://github.com/yugabyte/jdbc-yugabytedb
Source Code Management

Source Code Management

https://github.com/yugabyte/jdbc-yugabytedb

Download ysql

How to add to project

<!-- https://jarcasting.com/artifacts/com.yugabyte/ysql/ -->
<dependency>
    <groupId>com.yugabyte</groupId>
    <artifactId>ysql</artifactId>
    <version>42.2.7-yb-2</version>
</dependency>
// https://jarcasting.com/artifacts/com.yugabyte/ysql/
implementation 'com.yugabyte:ysql:42.2.7-yb-2'
// https://jarcasting.com/artifacts/com.yugabyte/ysql/
implementation ("com.yugabyte:ysql:42.2.7-yb-2")
'com.yugabyte:ysql:jar:42.2.7-yb-2'
<dependency org="com.yugabyte" name="ysql" rev="42.2.7-yb-2">
  <artifact name="ysql" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.yugabyte', module='ysql', version='42.2.7-yb-2')
)
libraryDependencies += "com.yugabyte" % "ysql" % "42.2.7-yb-2"
[com.yugabyte/ysql "42.2.7-yb-2"]

Dependencies

test (1)

Group / Artifact Type Version
se.jiderhamn : classloader-leak-test-framework jar 1.1.1

Project Modules

There are no modules declared in this project.

YugabyteDB JDBC Driver

This is a distributed JDBC driver for YugabyteDB SQL. This driver is based on the PostgreSQL JDBC Driver.

Features

This JDBC driver has the following features:

Cluster Awareness to eliminate need for a load balancer

This driver adds a YBClusterAwareDataSource that requires only an initial contact point for the YugabyteDB cluster, using which it discovers the rest of the nodes. Additionally, it automatically learns about the nodes being started/added or stopped/removed. Internally a connection pool is maintained for each node. A random live node is chosen to connect to the cluster and execute a statement. it will choose a live node to get a connection. When the connection is closed by the application, it is returned to the respective pool.

Topology Awareness to enable geo-distributed apps

NOTE: This feature is still in progress.

Shard awareness for high performance

NOTE: This feature is still in the design phase.

Get the Driver

From Maven

Add the following lines to your maven project.

<dependency>
  <groupId>com.yugabyte</groupId>
  <artifactId>jdbc-yugabytedb</artifactId>
  <version>42.2.7-yb-3</version>
</dependency>

Build locally

  1. Clone this repository.

    git clone https://github.com/yugabyte/jdbc-yugabytedb.git && cd jdbc-yugabytedb
    
  2. Build and install into your local maven folder.

     mvn clean install -DskipTests
    
  3. Finally, use it by adding the lines below to your project.

    <dependency>
        <groupId>com.yugabyte</groupId>
        <artifactId>jdbc-yugabytedb</artifactId>
        <version>42.2.7-yb-3-SNAPSHOT</version>
    </dependency> 

Use the Driver

  • Create the DataSource by passing an initial contact point

    String jdbcUrl = "jdbc:postgresql://127.0.0.1:5433/yugabyte";
    YBClusterAwareDataSource ds = new YBClusterAwareDataSource(jdbcUrl);
    
  • Use like a regular (pooling) DataSource

    // Using try-with-resources to auto-close the connection when done.
    try (Connection connection = ds.getConnection()) {
        // Use the connection as usual.
    } catch (java.sql.SQLException e) {
        // Handle/Report error.
    }
    
com.yugabyte

yugabyte

The high-performance distributed SQL database for global, internet-scale apps.

Versions

Version
42.2.7-yb-2
42.2.7-yb-1