Development Based on GaussDB JDBC
Java Database Connectivity (JDBC) is a Java API for running SQL statements. It provides a unified access API for different relational databases, based on which applications process data.
M-compatible databases can be developed based on GaussDB JDBC. For details, see "Application Development > Development Based on JDBC" in Developer Guide. Some functions of M-compatible databases are different from those of GaussDB. For details about the differences, see "Restrictions on Connecting Gauss JDBC to an M-compatible Database."
Restrictions on Connecting GaussDB JDBC to the M-compatible Database
- When the DriverManager.getConnection(String url, Properties info) method is used to create a database connection, the info parameter does not support the binaryTransfer, binaryTransferEnable, and binaryTransferDisable attributes.
- When the DriverManager.getConnection(String url, Properties info) method is used to create a database connection and the info parameter is set to mCompatible, some functions and behaviors are changed. The change is compatible with the MySQL JDBC 5.1 driver. For details, see "Application Development Guide > Development Based on JDBC > Development Procedure > Connecting to a Database > Connection Parameter Reference" in Developer Guide.
- For details about other GaussDB features that are not supported, see GaussDB Features That Are Not Supported by the M-compatible Database.
- When GaussDB JDBC is used to connect to a database and parameters are bound in the PBE scenario, you are advised to bind parameters based on the JDBC write mode listed in Table 1 Recommended JDBC write modes for different data types. Otherwise, the actual operator may be inconsistent with that selected during GSQL execution.
Table 1 Recommended JDBC write modes for different data types
|
Numeric Data Type |
MySQL Data Type |
DRS JDBC Write Mode |
|---|---|---|
|
Integer types |
BOOL |
prepStatement.setBoolean |
|
BOOLEAN |
prepStatement.setBoolean |
|
|
TINYINT[(M)][UNSIGNED] |
prepStatement.setShort/prepStatement.setInt |
|
|
SMALLINT[(M)][UNSIGNED] |
prepStatement.setShort/prepStatement.setInt |
|
|
MEDIUMINT[(M)][UNSIGNED] |
prepStatement.setInt/prepStatement.setInt |
|
|
INT[(M)][UNSIGNED] |
prepStatement.setInt/prepStatement.setLong |
|
|
INTEGER[(M)][UNSIGNED] |
prepStatement.setInt/prepStatement.setLong |
|
|
BIGINT[(M)][UNSIGNED] |
prepStatement.setLong/prepStatement.setBigDecimal |
|
|
Arbitrary precision types |
DECIMAL[( M[,D])][UNSIGNED] |
prepStatement.setBigDecimal |
|
NUMERIC[(M[,D])][UNSIGNED] |
prepStatement.setBigDecimal |
|
|
DEC[(M[,D])][UNSIGNED] |
prepStatement.setBigDecimal |
|
|
FIXED[(M[,D])] |
prepStatement.setBigDecimal |
|
|
FLOAT[(M,D)][UNSIGNED] |
prepStatement.setFloat(index, Float.parseFloat(val)) |
|
|
FLOAT(p)[UNSIGNED] |
prepStatement.setFloat(index, Float.parseFloat(val)) |
|
|
DOUBLE[(M,D)][UNSIGNED] |
prepStatement.setDouble |
|
|
DOUBLE PRECISION[(M,D)] |
prepStatement.setDouble |
|
|
REAL[(M,D)][UNSIGNED] |
prepStatement.setDouble |
|
|
Date and time data types |
DATE |
prepStatement.setDate |
|
DATETIME[(fsp)] |
prepStatement.setString/prepStatement.setTimestamp(1970/1/1 0:00:00) |
|
|
TIMESTAMP[ (fsp)] |
prepStatement.setString/prepStatement.setTimestamp |
|
|
TIME[(fsp)] |
prepStatement.setString |
|
|
YEAR |
prepStatement.setDate |
|
|
String data types |
CHAR[(M)] |
prepStatement.setObject(index, val, 1); |
|
VARCHAR(M) |
prepStatement.setString |
|
|
TINYTEXT |
prepStatement.setString |
|
|
TEXT |
prepStatement.setString |
|
|
MEDIUMTEXT |
prepStatement.setString |
|
|
LONGTEXT |
prepStatement.setString |
|
|
ENUM('value1','value2',...) |
prepStatement.setString |
|
|
SET('value1','value2',...) |
prepStatement.setString |
|
|
Binary data types |
BINARY[(M)] |
prepStatement.setBytes(index, val); |
|
VARBINARY(M) |
prepStatement.setBytes(index, val); |
|
|
TINYBLOB |
prepStatement.setBlob(index,PGBlob); |
|
|
BLOB |
prepStatement.setBlob(index,PGBlob); |
|
|
MEDIUMBLOB |
prepStatement.setBlob(index,PGBlob); |
|
|
LONGBLOB |
prepStatement.setBlob(index,PGBlob); |
|
|
BIT[(M)] |
prepStatement.setBigDecimal |
|
|
JSON data type |
JSON |
prepStatement.setString |
- When the getGeneratedKeys method is used to obtain the auto-increment values inserted in batches, the returned result is determined by the database driver according to the first auto-increment value, auto-increment step, and number of inserted records. If you specify values of the auto-increment column during batch insertion, the returned result may be different from the expected result.
- When the GUC parameter m_err_sql_dialect is set to "MySQL", you can enable error code replacement to replace the error codes and SQLSTATE values of GaussDB Kernel with those supported by M-compatible databases.
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