Obtaining the JAR Package of the Driver and Configuring the JDK Environment
Environment preparation includes obtaining the driver JAR package and configuring the JDK environment.
JDBC Packages
Obtain the driver JAR package from the release package GaussDB-Kernel_Database version number_OS version number_64bit_Jdbc.tar.gz. After the decompression, you will obtain the following JDBC packages in .jar format:
- 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. The Java code examples in this section use the opengaussjdbc.jar package by default. This driver package is used when both the PG database and GaussDB are accessed in a JVM process.
- gsjdbc4.jar: The main class name is org.postgresql.Driver, and the URL prefix of the database connection is jdbc:postgresql. This driver package applies to the scenario where services are migrated from the PostgreSQL database. 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.
- gscejdbc.jar: The main class name is com.huawei.gaussdb.jdbc.Driver. The URL prefix of database connections is jdbc:gaussdb. This driver package contains the dependent libraries related to encryption and decryption that need to be loaded to the encrypted database. This driver package is recommended in encrypted scenarios. Currently, only EulerOS is supported. Before using the gscejdbc.jar driver package, set the environment variable LD_LIBRARY_PATH. For details, see "Setting Encrypted Equality Queries > Using JDBC to Operate an Encrypted Database" in Feature Guide.
- gsjdbc200.jar: The main class name is com.huawei.gauss200.jdbc.Driver, and the URL prefix of the database connection is jdbc:gaussdb. This driver package applies to the scenario where services are migrated from GaussDB 200. 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 loading paths and URL prefixes of driver classes vary in different driver packages, but the 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.
- 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 GaussDB. 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.
Configuring the JDK Environment
JDK 1.8 must be configured on the client. JDK supports multiple platforms, such as Windows and Linux. The following example describes the configuration method using Windows:
- Enter the following command in the MS-DOS window (command prompt in Windows) to check the JDK version.
java -version
Check whether JDK 1.8 has been installed. If JDK is not installed, download the installation package from the official website and install it.
- Configure system environment variables.
- Right-click My computer and choose Properties.
- In the navigation pane, choose Advanced system settings.
- In the System Properties dialog box, click Environment Variables on the Advanced tab page.
- In the System variables area of the Environment Variables dialog box, click New or Edit to configure system variables. For details about the variables, 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
Click 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
Click New.
%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot