Struct
本章节描述在JDBC驱动使用java.sql.Struct类型时,Oracle与GaussDB的差异。
| 构造方式 | Oracle数据库 | GaussDB数据库 | 接口差异 |
|---|---|---|---|
| 1. StructDescriptor的静态构造方法构造StructDescriptor对象 2. 通过StructDescriptor构造Struct对象 | String typeName = "XXX"; Connection conn = getConnection(); Object[] attributes = null; StructDescriptor desc = StructDescriptor.createDescriptor(typeName, conn); Struct struct = new STRUCT(desc, conn, attributes); | String typeName = "xxx"; Connection conn = getConnection(); Object[] elements = null; StructDescriptor desc = StructDescriptor.getDescriptor(typeName, conn); Struct struct = new GaussStruct(desc, attributes); | |
| 通过Connection的createStruct标准接口构造Struct对象 | String typeName = "XXX"; Connection conn = getConnection(); Object[] attributes = null; Struct struct = conn.createStruct(typeName, attributes); | String typeName = "XXX"; Connection conn = getConnection(); Object[] attributes = null; Struct struct = conn.createStruct(typeName, attributes); |
| 方法名 | 返回值类型 | throws | GaussDB数据库 |
|---|---|---|---|
| getSQLTypeName() | String | SQLException | 支持 |
| getAttributes() | Object[] | SQLException | 支持 |
| getAttributes(java.util.Map<String,Class<?>> map) | Object[] | SQLException | 不支持 |
getSQLTypeName接口差异参考如下说明:
- 对于package类型,通过packageName.typeName形式构造的Struct,getSQLTypeName接口差异如下:
- OJDBC11返回packageName.typeName。
- OJDBC8返回packageName.typeName,在packageName和typeName满足以下条件时返回"packageName"."typeName":
- GaussDB返回schemaName.packageName.typeName,在schemaName、packageName和typeName满足以下条件时返回"schemaName"."packageName"."typeName":
schemaName/packageName/typeName有任意名称不符合首字符为字母或者下划线,其他字符为字母、数字或者下划线。
- 对于package类型,其他场景下getSQLTypeName接口差异如下:
- OJDBC11返回schemaName.packageName.typeName。
- OJDBC8返回schemaName.packageName.typeName,在schemaName、packageName和typeName满足以下条件时返回"schemaName"."packageName.typeName":
schemaName/packageName/typeName有任意名称不符合首字符为字母,其他字符为字母或者数字或者下划线。
- GaussDB返回schemaName.packageName.typeName,在schemaName、packageName和typeName满足以下条件时返回"schemaName"."packageName"."typeName":
schemaName/packageName/typeName有任意名称不符合首字符为字母或者下划线,其他字符为字母、数字或者下划线。
- 对于非package类型,getSQLTypeName接口差异如下:
- OJDBC11返回schemaName.typeName。
- OJDBC8返回schemaName.typeName,在schemaName和typeName满足以下条件时返回"schemaName"."typeName":
- GaussDB返回schemaName.typeName,在schemaName和typeName满足以下条件时返回"schemaName"."typeName":
| Attribute数据库类型 | 返回值中对应元素的Java类型(Oracle OJDBC8) | 返回值中对应元素的Java类型(Oracle OJDBC11) | 返回值中对应元素的Java类型(GaussDB) |
|---|---|---|---|
| CHAR | String | String | String |
| VARCHAR/VARCHAR2 | String | String | String |
| NCHAR | String | String | String |
| NVARCHAR2 | String | String | String |
| NUMBER | BigDecimal | BigDecimal | BigDecimal |
| NUMERIC | BigDecimal | BigDecimal | BigDecimal |
| DECIMAL | BigDecimal | BigDecimal | BigDecimal |
| INTEGER | BigDecimal | BigDecimal | Integer |
| SMALLINT | BigDecimal | BigDecimal | Short |
| DOUBLE PRECISION | BigDecimal | BigDecimal | Double |
| FLOAT | BigDecimal | BigDecimal | Double |
| REAL | BigDecimal | BigDecimal | Float |
| BINARY_DOUBLE | Double | Double | Double |
| BINARY_INTEGER | BigDecimal | Integer | Integer |
| BOOLEAN | BigDecimal | Integer | Boolean |
| TIMESTAMP | Timestamp | Timestamp | Timestamp |
| TIMESTAMP WITH TIME ZONE | TIMESTAMPTZ | TIMESTAMPTZ | Timestamp |
| BLOB | BLOB | BLOB | PGBlob |
| CLOB | CLOB | CLOB | PGClob |
| 集合类型/数组类型 | ARRAY | ARRAY | GaussArray |
| RECORD类型 | STRUCT | STRUCT | GaussStruct |
对于上述表格中未列举出的类型,GaussDB暂不支持。
| Attribute数据库类型 | Attribute入参支持的Java类型列表(Oracle) | Attribute入参支持的Java类型列表(GaussDB) | 差异说明 |
|---|---|---|---|
| CHAR | 任意Java类型 | Byte、Short、Integer、Long、BigInteger、BigDecimal、Float、Double、Character、Boolean、String、java.sql.Date、java.sql.Time、java.sql.Timestamp、PGClob |
|
| VARCHAR/VARCHAR2 | 任意Java类型 | Byte、Short、Integer、Long、BigInteger、BigDecimal、Float、Double、Character、Boolean、String、java.sql.Date、java.sql.Time、java.sql.Timestamp、PGClob | attribute入参支持的类型差异见表格。 |
| NCHAR | 任意Java类型 | Byte、Short、Integer、Long、BigInteger、BigDecimal、Float、Double、Character、Boolean、String、java.sql.Date、java.sql.Time、java.sql.Timestamp、PGClob | attribute入参支持的类型差异见表格。 |
| NVARCHAR2 | 任意Java类型 | Byte、Short、Integer、Long、BigInteger、BigDecimal、Float、Double、Character、Boolean、String、java.sql.Date、java.sql.Time、java.sql.Timestamp、PGClob | attribute入参支持的类型差异见表格。 |
| NUMBER | Byte、Short、Integer、Long、Float、Double、Boolean、BigDecimal、BigInteger、String、oracle.sql.NUMBER | Byte、Short、Integer、Long、Float、Double、Boolean、BigDecimal、BigInteger、String |
|
| NUMERIC | Byte、Short、Integer、Long、Float、Double、Boolean、BigDecimal、BigInteger、String、oracle.sql.NUMBER | Byte、Short、Integer、Long、Float、Double、Boolean、BigDecimal、BigInteger、String |
|
| DECIMAL | Byte、Short、Integer、Long、Float、Double、Boolean、BigDecimal、BigInteger、String、oracle.sql.NUMBER | Byte、Short、Integer、Long、Float、Double、Boolean、BigDecimal、BigInteger、String |
|
| INTEGER | Byte、Short、Integer、Long、Float、Double、Boolean、BigDecimal、BigInteger、String、oracle.sql.NUMBER | Byte、Short、Integer、Long、Float、Double、Boolean、BigDecimal、BigInteger、String |
|
| SMALLINT | Byte、Short、Integer、Long、Float、Double、Boolean、BigDecimal、BigInteger、String、oracle.sql.NUMBER | Byte、Short、Integer、Long、Float、Double、Boolean、BigDecimal、BigInteger、String |
|
| DOUBLE PRECISION | Byte、Short、Integer、Long、Float、Double、Boolean、BigDecimal、BigInteger、String、oracle.sql.NUMBER | Byte、Short、Integer、Long、Float、Double、Boolean、BigDecimal、BigInteger、String |
|
| FLOAT | Byte、Short、Integer、Long、Float、Double、Boolean、BigDecimal、BigInteger、String、oracle.sql.NUMBER | Byte、Short、Integer、Long、Float、Double、Boolean、BigDecimal、BigInteger、String |
|
| REAL | Byte、Short、Integer、Long、Float、Double、Boolean、BigDecimal、BigInteger、String、oracle.sql.NUMBER | Byte、Short、Integer、Long、Float、Double、Boolean、BigDecimal、BigInteger、String |
|
| BINARY_DOUBLE | byte[]、Double、oracle.sql.BINARY_DOUBLE | Byte、Short、Integer、Long、Float、Double、Boolean、BigDecimal、BigInteger、String |
|
| BINARY_INTEGER | Byte、Short、Integer、Long、Float、Double、Boolean、BigDecimal、BigInteger、AtomicInteger、AutomicLong、DoubleAccumulator、DoubleAddr、LongAccumulator、LondAdder、Striped64、String、oracle.sql.NUMBER | Byte、Short、Integer、Long、Float、Double、Boolean、BigDecimal、BigInteger、String |
|
| BOOLEAN | Byte、Short、Integer、Long、Float、Double、Boolean、BigDecimal、BigInteger、AtomicInteger、AutomicLong、DoubleAccumulator、DoubleAddr、LongAccumulator、LondAdder、Striped64、String、oracle.sql.NUMBER | Byte、Short、Integer、Long、Float、Double、Boolean、BigDecimal、BigInteger、String |
|
| TIMESTAMP | byte[]、java.sql.Date、String、java.sql.Time、java.sql.Timestamp、oracle.sql.TIMESTAMP、oracle.sql.DATE | java.util.Date、java.sql.Date、java.sql.Time、java.sql.Timestamp、LocalDateTime、String | attribute入参支持的类型差异见表格。 |
| TIMESTAMP WITH TIME ZONE | java.sql.Date、Calendar、java.util.Date、LocalDate、LocalDateTime、LocalTime、OffsetDateTime、OffsetTime、String、java.sql.Time、java.sql.Timestamp、oracle.sql.TIMESTAMP、oracle.sql.TIMESTAMPTZ、oracle.sql.TIMESTAMPLTZ、ZonedDateTime | java.util.Date、java.sql.Date、java.sql.Time、java.sql.Timestamp、LocalDateTime、String |
|
| BLOB | oracle.sql.BLOB、oracle.jdbc.driver.OracleBlob | PGBlob |
|
| CLOB | oracle.sql.CLOB、oracle.jdbc.driver.OracleClob | PGClob |
|
| 集合类型/数组类型 | ARRAY、Object | GaussArray、Object | |
| RECORD类型 | STRUCT、Object[] | GaussStruct、Object[] |
- 构造Struct时,若传入元素的Java类型不符合目标类型,会进行相应的隐式转换操作,对于不同的数据库元素类型,支持传入的元素的Java类型差异见上表。
- 对于上述表格中未列举出的类型,GaussDB暂不支持。
- 构造方法需要提供属性数组,上述表格描述的是数组中每一个attribute对应的差异。