YugabyteDB JDBC Smart Driver is a distributed JDBC driver for YSQL built on the PostgreSQL JDBC driver, with additional connection load balancing features.

For Java applications, the JDBC driver provides database connectivity through the standard JDBC application program interface (APIs) available on the Java platform.

CRUD operations

The following sections demonstrate how to perform common tasks required for Java application development.

To start building your application, make sure you have met the prerequisites.

Step 1: Set up the client dependencies

Maven dependency

If you are using Maven, add the following to your pom.xml of your project.


<!-- https://mvnrepository.com/artifact/com.zaxxer/HikariCP -->

Install the added dependency using mvn install.

Gradle dependency

If you are using Gradle, add the following dependencies to your build.gradle file:

implementation 'com.yugabyte:jdbc-yugabytedb:42.3.0'
implementation 'com.zaxxer:HikariCP:4.0.3'

Step 2: Set up the database connection

After setting up the dependencies, implement the Java client application that uses the YugabyteDB JDBC driver to connect to your YugabyteDB cluster and run query on the sample data.

Set up the driver properties to configure the credentials and SSL Certificates for connecting to your cluster. Java Apps can connect to and query the YugabyteDB database using the java.sql.DriverManager class. All the JDBC interfaces required for working with YugabyteDB database are part of java.sql.* package.

Use the DriverManager.getConnection method for getting connection object for the YugabyteDB database, which can be used for performing DDLs and DMLs against the database.

The following table describes the connection parameters required to connect, including smart driver parameters for uniform and topology load balancing.

JDBC Parameter Description Default
hostname Hostname of the YugabyteDB instance localhost
port Listen port for YSQL 5433
database Database name yugabyte
user User connecting to the database yugabyte
password User password yugabyte
load-balance Uniform load balancing Defaults to upstream driver behavior unless set to 'true'
topology-keys Topology-aware load balancing If load-balance is true, uses uniform load balancing unless set to comma-separated geo-locations in the form cloud.region.zone.

The following is an example JDBC URL for connecting to YugabyteDB.

jdbc://yugabytedb://hostname:port/database?user=yugabyte&password=yugabyte&load-balance=true& \


The following table describes the connection parameters required to connect using SSL.

JDBC Parameter Description Default
ssl Enable SSL client connection false
sslmode SSL mode require
sslrootcert Path to the root certificate on your computer ~/.postgresql/

The following is an example JDBC URL for connecting to a YugabyteDB cluster with SSL encryption enabled.

jdbc:yugabytedb://hostname:port/database?user=yugabyte&password=yugabyte&load-balance=true& \

If you created a cluster on YugabyteDB Managed, use the cluster credentials and download the SSL Root certificate.

Step 3: Write your application

Create a new Java class called QuickStartApp.java in the base package directory of your project as follows:

touch ./src/main/java/com/yugabyte/QuickStartApp.java

Copy the following code to set up a YugabyteDB table and query the table contents from the Java client. Be sure to replace the connection string yburl with credentials of your cluster and SSL certificate if required.

package com.yugabyte;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;

public class QuickStartApp {
  public static void main(String[] args) throws ClassNotFoundException, SQLException {
    String yburl = "jdbc:yugabytedb://";
    Connection conn = DriverManager.getConnection(yburl);
    Statement stmt = conn.createStatement();
    try {
        System.out.println("Connected to the YugabyteDB Cluster successfully.");
        stmt.execute("DROP TABLE IF EXISTS employee");
        stmt.execute("CREATE TABLE IF NOT EXISTS employee" +
                    "  (id int primary key, name varchar, age int, language text)");
        System.out.println("Created table employee");

        String insertStr = "INSERT INTO employee VALUES (1, 'John', 35, 'Java')";
        System.out.println("EXEC: " + insertStr);

        ResultSet rs = stmt.executeQuery("select * from employee");
        while (rs.next()) {
          System.out.println(String.format("Query returned: name = %s, age = %s, language = %s",
                                          rs.getString(2), rs.getString(3), rs.getString(4)));
    } catch (SQLException e) {

Run the project QuickStartApp.java using the following command:

mvn -q package exec:java -DskipTests -Dexec.mainClass=com.yugabyte.QuickStartApp

You should see output similar to the following:

Connected to the YugabyteDB Cluster successfully.
Created table employee
Inserted data: INSERT INTO employee (id, name, age, language) VALUES (1, 'John', 35, 'Java');
Query returned: name=John, age=35, language: Java

If you receive no output or an error, check the parameters in the connection string.

Learn more