Help Center> GaussDB> Centralized_2.x> Application Development Guide> Development Based on JDBC> JDBC Package, Driver Class, and Environment Class
Updated on 2023-10-23 GMT+08:00

JDBC Package, Driver Class, and Environment Class

JDBC Package

Obtain release package provided by GaussDB.

Obtain the GaussDB-Kernel_VxxxRxxxCxx.x-OS version number-64bit-Jdbc.tar.gz package from the release package. After the decompression, you will obtain the following JDBC packages in .jar format:
  • gsjdbc4.jar: The driver class name and loading path are the same as those of PostgreSQL driver, which facilitates the migration of services running on PostgreSQL. However, some interfaces supported by gsjdbc4.jar are different from those supported by PostgreSQL and need to be adjusted on the service side.
  • gsjdbc200.jar: The driver class name and loading path are the same as those of GaussDB 200, which facilitates the migration of services running on GaussDB 200. However, some interfaces supported by gsjdbc200.jar are different from those supported by GaussDB 200 and 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 PostgreSQL and GaussDB are accessed in a JVM process.
    • The loading paths of driver classes in different driver packages are different, but the interface functions are the same.
    • The gsjdbc4 driver package cannot be used to operate the PostgreSQL database. Although the connection can be successfully established in some versions, some interface behaviors are different from those of PostgreSQL JDBC, which may cause unknown errors.
    • The PostgreSQL driver package cannot be used to operate the GaussDB database. Although the connection can be successfully established in some versions, some interface behaviors are different from those of GaussDB JDBC, which may cause unknown errors.

Driver Class

Before establishing a database connection, load the org.postgresql.Driver database driver class.

  1. GaussDB is compatible with PostgreSQL in the use of JDBC. Therefore, when two JDBC drivers are used in the same process, class names may conflict.
  2. Compared with the PostgreSQL driver, the GaussDB JDBC driver has the following enhanced features:
    1. The SHA256 encryption mode is supported for login.
    2. The third-party log framework that implements the sf4j API can be connected.
    3. DR failover is supported.

Environment Class

JDK 1.8 must be configured on the client. The configuration method is as follows:

  1. In the MS-DOS window, run java -version to check the JDK version. Ensure that the version is JDK 1.8. If JDK is not installed, download the installation package from the official website and install it.
  2. Configure system environment variables.

    1. Right-click My computer and choose Properties.
    2. In the navigation pane, choose Advanced system settings.
    3. In the System Properties dialog box, click Environment Variables on the Advanced tab page.
    4. In the System variables area of the Environment Variables dialog box, click New or Edit to configure system variables. For details, see Table 1.
      Table 1 Description

      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;