Updated on 2025-07-15 GMT+08:00

JDBC Package, Driver Class, and Environment Class

Obtaining the Driver Package

Download the driver package and its verification package listed in Table 1.

Table 1 Driver package download list

Version

Download Address

V2.0-2.x

Driver package

Verification package for the driver package

To prevent a software package from being tampered with during transmission or storage, download the corresponding verification package and perform the following steps to verify the software package:
  • Verifying the software package integrity on a Linux server:
    1. Upload the software package and verification package to the same directory on the VM.
    2. Run the following command to verify the integrity of the software package:

      cat GaussDB_driver.zip.sha256 | sha256sum --check

      If OK is displayed in the command output, the verification is successful.

      GaussDB_driver.zip: OK
  • Verifying the software package integrity on a Windows server:
    1. Press Win+R to open the Run dialog box. Type cmd in the text box and press Enter to open the Command Prompt window.
    2. Run the following command to obtain the hash value of the driver package:

      certutil -hashfile {local_directory_of_the_driver_package}\{driver_package_name} sha256

      • Replace {local_directory_of_the_driver_package} with the actual download path, for example, C:\Users.
      • Replace {driver_package_name} with the name of the downloaded driver package, for example, GaussDB_driver.zip.

      Example: certutil -hashfile C:\Users\GaussDB_driver.zip sha256

    3. Compare the hash value obtained in 2 with the hash value of the verification package obtained in Table 1.
      • If they are consistent, the verification is successful.
      • If they are inconsistent, download the driver package again and repeat 1 to 3 to verify the driver package.

Decompressing the Driver Package

Decompress the obtained driver package, find the JDBC driver package GaussDB-Kernel_Database version number_OS_64bit_Jdbc.tar.gz, and decompress it. After the decompression, you will obtain the following driver packages in JAR format:

  • gsjdbc4.jar: This driver package applies to the scenario where services are migrated from PG. The driver class and loading path are the same as those before the migration, but the supported APIs are different. The APIs that are not supported need to be adjusted on the service side.
  • opengaussjdbc.jar: The main class name is com.huawei.opengauss.jdbc.Driver. The URL prefix of the database connection is jdbc:opengauss. This driver package is recommended. This driver package is used when both PG and GaussDB are accessed in a JVM process.
  • The loading paths and URL prefixes of driver classes vary in different driver packages, but their functions are the same.
  • The JAR packages of the JDBC release package are classified by architecture. The gscejdbc.jar package can be used only when it is consistent with the deployment environment. Other JAR packages do not need to be consistent with the deployment environment.
  • gsjdbc200.jar: This driver package applies to the scenario where services are migrated from Gauss200. The driver class and loading path are the same as those before the migration, but the supported APIs are different. The APIs that are not supported need to be adjusted on the service side.
  • The gsjdbc4 driver package cannot be used to operate the PG database. Although the connection can be successfully established in some versions, some API behaviors are different from those of PG JDBC, which may cause unknown errors.
  • The PG driver package cannot be used to operate the GaussDB database. Although the connection can be successfully established in some versions, some API behaviors are different from those of GaussDB JDBC, which may cause unknown errors.

Driver Class

Before creating a database connection, load the database driver class org.postgresql.Driver (decompressed from gsjdbc4.jar).

  1. GaussDB is compatible with PG in the use of JDBC. Therefore, when two JDBC drivers are used in the same process, class names may conflict.
  2. JDBC of this version does not support identity & access management suite (IAM) for authentication.
  3. Compared with the PG driver, the GaussDB JDBC driver has the following enhanced features:
    1. SHA-256 is supported for encrypted login.
    2. The third-party log framework that implements the sf4j API can be connected.
    3. Distributed load balancing at the connection level is supported.
    4. DR failover is supported.

Environment Class

JDK 1.8 must be configured on the client. JDK supports multiple platforms such as Windows and Linux. The following uses Windows as an example to describe how to configure JDK.

  1. Enter java -version in the MS-DOS window (command prompt in Windows) to check the JDK version. Ensure that the JDK version is JDK 1.8. If the JDK is not installed, download the installation package and install it.
  2. On the Windows desktop, right-click This PC and choose Properties from the shortcut menu.
  3. In the displayed System window, click Advanced system settings in the navigation tree on the left.
  4. In the System Properties dialog box, click Environment Variables in the lower right corner.
  5. In the System variables area of the Environment Variables dialog box that is displayed, set the following variables.

    Variable

    Operation

    Variable Value

    JAVA_HOME

    • If the variable exists, click Edit.
    • If the variable does not exist, click New.

    Specifies the Java installation directory.

    Example: C:\Program Files\Java\jdk1.8.0_131

    Path

    Edit

    • If JAVA_HOME is configured, add %JAVA_HOME%\bin before the variable value.
    • If JAVA_HOME is not configured, add the full Java installation path before the variable value:

      C:\Program Files\Java\jdk1.8.0_131\bin;

    CLASSPATH

    New

    .;%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar;

  6. Click OK and close the windows one by one.